Skip to content

Commit

Permalink
Merge pull request #3702 from mathesar-foundation/list_tables_empty
Browse files Browse the repository at this point in the history
In SQL, return an empty array when a schema has no tables
  • Loading branch information
Anish9901 authored Jul 23, 2024
2 parents 3f1e2f8 + 709a60c commit fee9d57
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions db/sql/00_msar.sql
Original file line number Diff line number Diff line change
Expand Up @@ -838,13 +838,16 @@ Each returned JSON object in the array will have the form:
Args:
sch_id: The OID or name of the schema.
*/
SELECT jsonb_agg(
jsonb_build_object(
'oid', pgc.oid::bigint,
'name', pgc.relname,
'schema', pgc.relnamespace::bigint,
'description', msar.obj_description(pgc.oid, 'pg_class')
)
SELECT coalesce(
jsonb_agg(
jsonb_build_object(
'oid', pgc.oid::bigint,
'name', pgc.relname,
'schema', pgc.relnamespace::bigint,
'description', msar.obj_description(pgc.oid, 'pg_class')
)
),
'[]'::jsonb
)
FROM pg_catalog.pg_class AS pgc
LEFT JOIN pg_catalog.pg_namespace AS pgn ON pgc.relnamespace = pgn.oid
Expand Down
2 changes: 1 addition & 1 deletion db/sql/test_00_msar.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2696,7 +2696,7 @@ BEGIN

-- Test table info for schema 'alice' that contains no tables
RETURN NEXT is(
alice_table_info, null
alice_table_info, '[]'::jsonb
);
END;
$$ LANGUAGE plpgsql;
Expand Down

0 comments on commit fee9d57

Please sign in to comment.