Skip to content

WHPG19: named / NO INHERIT / NOT VALID not-null constraints are not reproduced #53

Description

@Bonartze

On WHPG19 (PG18), a column NOT NULL is also represented as a pg_constraint row with contype = 'n'. PR #52 excludes those rows from GetConstraints (backup/queries_shared.go) because the column definition already carries attnotnull, which stops the constraint being emitted twice.

That is correct as far as it goes, but a PG18 not-null constraint can carry three things the column-level NOT NULL cannot reproduce:

  • a name (conname)
  • NO INHERIT (connoinherit)
  • NOT VALID (convalidated = false, added by a379061a2)

The first two are cosmetic. NOT VALID is not: a table whose not-null constraint has never been validated may legitimately contain NULLs, and gpbackup currently emits an enforced NOT NULL for it — so the restore's COPY fails on rows the source accepted.

pg_dump handles this in the PG18 branch of getTableAttrs, selecting

co.conname AS notnull_name,
co.connoinherit AS notnull_noinherit,
co.conislocal AS notnull_islocal,
NOT co.convalidated AS notnull_invalid

and emitting CONSTRAINT <name> NOT NULL <col> [NO INHERIT] [NOT VALID] in the column list instead of a bare NOT NULL.

Doing the same in gpbackup means carrying those fields on ColumnDefinition and changing how PrintRegularTableCreateStatement renders the not-null part of a column — a heavily tested path, which is why it was left out of #52 rather than rushed in.

Raised from review of #52 (#52 (comment)); the reviewer was happy for it to be a follow-up given it is an edge case.

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