Skip to content

Can't subscribe to an query using json_object, json_group_array and json_object #325

@gorbak25

Description

@gorbak25

When trying to subscribe to an in sql generated json via this query

SELECT json_object(
  'foos', (SELECT json_group_array(json_object('id', foo.id)) FROM foo),
  'bars', (SELECT json_group_array(json_object('id', bar.id)) FROM bar)
) as test;

The subscription fails with this error

2025-07-16T14:27:51.061053Z  INFO corro_agent::api::public::pubsub: Received subscription request for query: SELECT json_object(
   'foos', (SELECT json_group_array(json_object('id', foo.id)) FROM foo),
   'bars', (SELECT json_group_array(json_object('id', bar.id)) FROM bar)
 ) as test;
2025-07-16T14:27:51.062148Z  INFO corro_types::pubsub: Initializing subscription at /run/subscriptions/bcf32d6a3487407c96f06e549b1f9757 sql_hash=0a8d7c7f829dcc54 sub_id=bcf32d6a-3487-407c-96f0-6e549b1f9757
2025-07-16T14:27:51.067115Z ERROR corro_types::pubsub: could not create subscription: at least 1 table is required in FROM / JOIN clause sub_id=bcf32d6a-3487-407c-96f0-6e549b1f9757

This is weird as at first glance the sql parser corrosion uses should process function calls and sub-queries properly

Expr::FunctionCall { args, .. } => {

The AST comming from sqlite3_parser 0.12.0 doesn't look too concerning

Ok(Some(Stmt(Select(Select { with: None, body: SelectBody { select: Select { distinctness: None, columns: [Expr(FunctionCall { name: Id("json_object"), distinctness: None, args: Some([Literal(String("'foos'")), Subquery(Select { with: None, body: SelectBody { select: Select { distinctness: None, columns: [Expr(FunctionCall { name: Id("json_group_array"), distinctness: None, args: Some([FunctionCall { name: Id("json_object"), distinctness: None, args: Some([Literal(String("'id'")), Qualified(Name("foo"), Name("id"))]), order_by: None, filter_over: None }]), order_by: None, filter_over: None }, None)], from: Some(FromClause { select: Some(Table(QualifiedName { db_name: None, name: Name("foo"), alias: None }, None, None)), joins: None, op: None }), where_clause: None, group_by: None, window_clause: None }, compounds: None }, order_by: None, limit: None }), Literal(String("'bars'")), Subquery(Select { with: None, body: SelectBody { select: Select { distinctness: None, columns: [Expr(FunctionCall { name: Id("json_group_array"), distinctness: None, args: Some([FunctionCall { name: Id("json_object"), distinctness: None, args: Some([Literal(String("'id'")), Qualified(Name("bar"), Name("id"))]), order_by: None, filter_over: None }]), order_by: None, filter_over: None }, None)], from: Some(FromClause { select: Some(Table(QualifiedName { db_name: None, name: Name("bar"), alias: None }, None, None)), joins: None, op: None }), where_clause: None, group_by: None, window_clause: None }, compounds: None }, order_by: None, limit: None })]), order_by: None, filter_over: None }, Some(As(Name("test"))))], from: None, where_clause: None, group_by: None, window_clause: None }, compounds: None }, order_by: None, limit: None }))))

I'm using corrosion commit 85a0aed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions