You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
list_tables reports a foreign key once per partition when a partitioned table is involved #507
list_tables (verbose: true) reports the FK copies Postgres creates for partitions as real foreign keys. One declared FK is listed once per partition, and every partition gets an FK it never declared.
First noted by @Rjabov at the end of #381; it hasn't been filed since, so I'm picking it up.
To Reproduce
createtableorders (id intprimary key) partition by hash (id);
createtableorders_p0 partition of orders for values with (modulus 2, remainder 0);
createtableorders_p1 partition of orders for values with (modulus 2, remainder 1);
createtableorder_items (order_id intreferences orders (id));
createtableusers (id intprimary key);
createtableevents (user_id intreferences users (id), created_at date) partition by range (created_at);
createtableevents_2025 partition of events for valuesfrom ('2025-01-01') to ('2026-01-01');
createtableevents_2026 partition of events for valuesfrom ('2026-01-01') to ('2027-01-01');
Two FKs are declared. foreign_key_constraints per table:
table
reported
expected
order_items
3: order_items_order_id_fkey, …_fkey1, …_fkey2
1
users
3: events_user_id_fkey ×3
1
orders_p0, orders_p1, events_2025, events_2026
1 each
none
The count grows with partitions: with 12 monthly partitions, users lists the same FK 13 times.
Root cause
The relationships subquery in pg-meta/tables.sql reads every contype = 'f' row of pg_constraint, including the clones Postgres creates for partitions (conparentid <> 0). pg_dump skips them with the same predicate (getConstraints: contype = 'f' AND conparentid = 0).
Expected behavior
Each FK is reported once, on the tables it connects. FKs declared directly on a partition are still reported.
System information
@supabase/mcp-server-supabase at main (ed5084d)
PostgreSQL 15.19 and 17.11; PGlite (PostgreSQL 16.4) in the test harness
Additional context
Fix and regression test are ready; PR to follow.
Separate question, not part of the fix: partitions are listed as standalone tables next to their parent. Is that intended, or should list_tables mark or group them?
Thanks, added in #508. partition_of is in both compact and verbose output and points to the immediate parent, so a sub-partition names its own parent rather than the root.
Activity
mattrossman commentedon Nov 2, 2026
I think if we're removing the duplicate foreign keys, it'd be helpful to have a marker so the relationship is still communicated.
Something like:
{ "name": "public.events_2025", "partition_of": "public.events", "columns": [...], "primary_keys": [...] }sarpaydemir commentedon Nov 2, 2026
Thanks, added in #508.
partition_ofis in both compact and verbose output and points to the immediate parent, so a sub-partition names its own parent rather than the root.fix(pg-meta): report partition FKs once and add partition_of to list_…