Skip to content

fix(pg-meta): return complete check expressions for NOT VALID and NO INHERIT constraints - #517

Merged
barryroodt merged 1 commit into
supabase:mainfrom
irisfield:fix/pg-meta-check-constraint-suffix
Nov 5, 2026
Merged

barryroodt merged 1 commit into
supabase:mainfrom
irisfield:fix/pg-meta-check-constraint-suffix

Conversation

@irisfield

@irisfield irisfield commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

Fixes #516

list_tables (verbose) builds each column's check by removing CHECK ( and the last character from pg_get_constraintdef by character count. When the constraint has a NOT VALID or NO INHERIT suffix, the cut lands inside the suffix.

What is the new behavior?

The check_constraints subquery in columns.sql reads the expression with pg_get_expr(conbin, conrelid, true), which returns the expression without any constraint options. Checks without a suffix return the same text as before.

constraint before after
check (a > 0) not valid a > 0) NOT VALI a > 0
check (b > 0) no inherit b > 0) NO INHERI b > 0
check (c > 0) c > 0 c > 0

No change to tool names, descriptions, or input and output schemas.

How to Review

  1. Check expression

    • packages/mcp-server-supabase/src/pg-meta/columns.sql
    • The check_constraints subquery now selects pg_get_expr(...) in place of the substring(pg_get_constraintdef(...)).
  2. Tests

    • packages/mcp-server-supabase/src/server.database.test.ts
    • list tables returns the check expression for NOT VALID and NO INHERIT constraints checks the check returned by list_tables for a NOT VALID, a NO INHERIT and a plain constraint.

Review questions

  • Is pg_get_expr(conbin, conrelid, true) the output you want for check? It matches the previous text for constraints without options.
  • Should list_tables say when a check is NOT VALID (not yet validated against existing rows)? This PR returns the expression only and does not add a field.
  • Is one plain constraint in the test enough to guard the unchanged output, or should it also cover the regex, numeric and IN (...) shapes?
  • Does the test check the check value list_tables returns, rather than the SQL that builds it?

Verification

  • The new test fails on main with a > 0) NOT VALI and b > 0) NO INHERI, and passes with the fix.
  • pnpm --filter @supabase/mcp-server-supabase test:unit --run: 771 passed.
  • pnpm format:check: clean.
  • On a hosted project (Postgres 17.11), running the built server over stdio with the SQL from list_tables returns truncated check expressions for NOT VALID and NO INHERIT constraints #516: main returns a > 0) NOT VALI and b > 0) NO INHERI; this branch returns a > 0, b > 0 and c > 0.

…INHERIT constraints

list_tables cut the check expression out of pg_get_constraintdef by
character count, so the NOT VALID or NO INHERIT suffix shifted the cut
and returned text such as "a > 0) NOT VALI". Read the expression with
pg_get_expr instead.

Fixes supabase#516
@irisfield
irisfield requested a review from a team as a code owner November 5, 2026 06:06

@barryroodt barryroodt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @irisfield, nice catch, and the write-up made this easy to review!

On your first question: yes, pg_get_expr is what we want. I compared old vs new output on PGlite (Postgres 17.5) for a handful of shapes (regex, IN list, BETWEEN with AND, date + jsonb casts, OR IS NULL) and they match. Only the NOT VALID / NO INHERIT cases change.

On the second one, flagging NOT VALID in the output is fine to leave out of this PR.

@barryroodt
barryroodt merged commit c54bb40 into supabase:main Nov 5, 2026
3 of 5 checks passed
@supabase-releaser supabase-releaser Bot mentioned this pull request Nov 5, 2026
barryroodt pushed a commit that referenced this pull request Nov 5, 2026
🤖 I have created a release *beep* *boop*
---


<details><summary>mcp-server-supabase: 0.16.0</summary>

##
[0.16.0](mcp-server-supabase-v0.15.0...mcp-server-supabase-v0.16.0)
(2026-11-05)


### Features

* bound run_notebook cost
([#511](#511))
([e90d110](e90d110))
* **mcp-server-supabase:** run selected notebook cells
([#514](#514))
([8d04248](8d04248))
* **notebooks:** add delete_notebook tool with elicitation confirmation
([#510](#510))
([f36f74a](f36f74a))
* **notebooks:** enable create_notebook and run_notebook tools
([#509](#509))
([addc4e5](addc4e5))


### Bug Fixes

* **feedback:** accept null project_id and surface the feedback length
limit ([#521](#521))
([994f56c](994f56c))
* hint agents to re-copy malformed project refs
([#522](#522))
([0c650bf](0c650bf))
* **notebooks:** return caller errors for client-caused notebook
refusals ([#512](#512))
([5f0d393](5f0d393))
* **pg-meta:** report partition FKs once and add partition_of to
list_tables ([#508](#508))
([2c7fa82](2c7fa82))
* **pg-meta:** return complete check expressions for NOT VALID and NO
INHERIT constraints ([#517](#517))
([c54bb40](c54bb40))
* **sql:** skip destructive confirmation for planner-only EXPLAIN
([#519](#519))
([95745e5](95745e5))
* tolerate non-URL edge function paths in api platform
([#438](#438))
([00d07a4](00d07a4))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: supabase-releaser[bot] <223506987+supabase-releaser[bot]@users.noreply.github.com>
@irisfield

Copy link
Copy Markdown
Contributor Author

Thanks for the review and for running the extra comparisons!

@irisfield
irisfield deleted the fix/pg-meta-check-constraint-suffix branch November 11, 2026 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

list_tables returns truncated check expressions for NOT VALID and NO INHERIT constraints

2 participants