Relationship column lists are null for dotted/mixed-case schemas

Open Beginner friendly
#1,147 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
postgresql, typescript
Domain
databases

Research direction

Start at the definitions of TABLE_RELATIONSHIPS_SQL and VIEWS_KEY_DEPENDENCIES_SQL, then trace the relationships.list entry point used by PostgresMetaRelationships. Reproduce the issue with the provided dotted-schema SQL and includedSchemas value. Done means relationship results populate columns and referenced_columns for dotted and mixed-case schemas.

Written by the indexing model from the issue text.

Description

Bug

TABLE_RELATIONSHIPS_SQL / VIEWS_KEY_DEPENDENCIES_SQL filter some clauses with connamespace::regnamespace::text, while the outer table filter correctly uses nspname.

For schemas that need quoting, those differ:

nspname ::regnamespace::text
odd.schema "odd.schema"
MySchema "MySchema"

So IN ('odd.schema') matches nspname but misses regnamespace::text. The FK lateral still returns a row (aggregate), but with null columns / referenced_columns.

Impact

Typegen relationship inference (PostgresMetaRelationships) drops FK column info for projects that use dotted or mixed-case schema names.

Repro

create schema "odd.schema";
create table "odd.schema".parent (id int8 primary key);
create table "odd.schema".child (
  id int8 primary key,
  parent_id int8 references "odd.schema".parent (id)
);

Then relationships.list({ includedSchemas: ['odd.schema'] }) — relationship exists but columns / referenced_columns are null.

Expected

Filter by nspname (or oid via pg_namespace) consistently so column lists are populated.

Dominant language
TypeScript
Stars
1.2k
Forks
223
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from supabase/postgres-meta

All issues in supabase/postgres-meta

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.