Skip to content

Column check introspection corrupts expressions with NOT VALID / NO INHERIT #1143

Description

@hsusul

Bug

Column check is extracted by stripping a fixed prefix/suffix from pg_get_constraintdef(...), assuming the def is exactly CHECK (...).

When the constraint has a suffix (NOT VALID, NO INHERIT), the length heuristic returns a corrupted expression:

constraintdef returned check
CHECK (id > 0) NOT VALID id > 0) NOT VALI
CHECK (id > 0) NO INHERIT id > 0) NO INHERI

Studio then shows / may round-trip an invalid check expression.

Repro

create table public.t (id int8);
alter table public.t add constraint t_id_check check (id > 0) not valid;

Then columns.retrieve / list — check is not id > 0.

Expected

check should be the expression only (id > 0), using pg_get_expr(conbin, conrelid) (with one outer paren pair stripped to preserve the existing API shape).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions