Repository navigation
Conversation
information_schema.table_constraints and referential_constraints only list constraints on tables the current role owns or holds a non-SELECT privilege on. Read-only users therefore saw no foreign keys, and FK navigation (o / O in results) silently did nothing. Query pg_constraint directly, which is visible to every role. Partition child constraints are skipped via conparentid = 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
quote_literal rendered strings as convert_from(decode(<hex>)), which is typed text. Jumping through a uuid (or other non-text) key then failed with "operator does not exist: uuid = text". Emit a dollar-quoted literal instead. It is still independent of standard_conforming_strings / backslash settings, but stays untyped so PostgreSQL coerces it to the column type. The tag is extended when the value would collide with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
FK navigation (
o/Oin results) silently does nothing on PostgreSQL when connected as a role that only hasSELECTon the tables (typical for read-only prod/stage users).PostgresBaseAdapter.get_foreign_keys/get_referencing_foreign_keysread frominformation_schema.table_constraintsandreferential_constraints. Per the PostgreSQL docs, those views only list constraints on tables the current role owns or holds a privilege other than SELECT on. A read-only role therefore gets an empty list, so no FK metadata is attached to the results and neither key has anything to act on.Fix
PostgreSQLAdapter(andSupabaseAdapter, which inherits it) now reads FKs frompg_catalog.pg_constraint. The catalog is visible to every role. It usesunnest(conkey, confkey) WITH ORDINALITYso composite keys keep their column order. Partition child constraints are skipped withconparentid = 0, so a partitioned table's FKs appear once.CockroachDB and Redshift keep their existing queries, because their catalog support differs.
Second fix: jumping through uuid keys
With FKs now visible, jumping through a
uuidkey failed:quote_literalproducedconvert_from(...), an expression typedtext. It now produces a dollar-quoted literal ($sqlit$…$sqlit$). That is still independent ofstandard_conforming_strings, but it is untyped, so PostgreSQL coerces it to the column type (uuid, int, date, …). If the value contains the tag, the tag is extended ($sqlit1$, …). Checked on PostgreSQL: values with uuid, int, backslash+quote and an embedded tag all compare correctly.Verification
NOLOGINrole with onlyUSAGE+SELECTon the schema, inside a rolled-back transaction:information_schemaquery: 0 referencing FKspg_catalogquery: 3 referencing FKs, 2 outgoing (all correct)Oon a referencedidcolumn opens the picker and runs the lookup query.tests/unit/test_postgres_foreign_keys_catalog.py. The full unit and UI suites pass (1805 passed, 3 skipped).🤖 Generated with Claude Code