postgres.git / summary / log / commit / refs

commit    3a9cf1c925a0430264be3bd993f10b75c408b05e
Author:   Álvaro Herrera <alvherre@kurilemu.de>
Date:     Sat Mar 07 13:28:16 2026 +0000
First released in: 18.4

    Fix invalid boolean if-test
    
    We were testing the truth value of the array of booleans (which is
    always true) instead of the boolean element specific to the affected
    table column.
    
    This causes a binary-upgrade dump fail to omit the name of a constraint;
    that is, the correct constraint name is always printed, even when it's
    not needed.  The affected case is a binary-upgrade dump of a not-null
    constraint in an inherited column, which must in addition have no
    comment.
    
    Another point is that in order for this to make a difference, the
    constraint must have the default name in the child table.  That is, the
    constraint must have been created _in the parent table_ with the name
    that it would have in the child table, like so:
      CREATE TABLE parent (a int CONSTRAINT child_a_not_null NOT NULL);
      CREATE TABLE child () INHERITS (parent);
    Otherwise, the correct name must be printed by binary-upgrade pg_dump
    anyway, since it wouldn't match the name produced at the parent.
    
    Moreover, when it does hit, the pre-18-compatibility code (which has to
    work with a constraint that has no name) gets involved and uses the
    UPDATE on pg_constraint using the conkey instead of column name ... and
    so everything ends up working correctly AFAICS.
    
    I think it might cause a problem if the table and column names are
    overly long, but I didn't want to spend time investigating further.
    
    Still, it's wrong code, and static analyzers have twice complained about
    it, so fix it by adding the array index accessor that was obviously
    meant.
    
    Reported-by: Ranier Vilela <ranier.vf@gmail.com>
    Reported-by: George Tarasov <george.v.tarasov@gmail.com>
    Backpatch-through: 18
    Discussion: https://postgr.es/m/CAEudQAo7ah=4TDheuEjtb0dsv6bHoK7uBNqv53Tsub2h-xBSJw@mail.gmail.com
    Discussion: https://postgr.es/m/f3029f25-acc9-4cb9-a74f-fe93bcfb3a27@gmail.com


src/bin/pg_dump/pg_dump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 077da79ead8..8f6332d731f 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -9916,7 +9916,7 @@ determineNotNullFlags(Archive *fout, PGresult *res, int r, */ if ((dopt->binary_upgrade && !tbinfo->ispartition && - !tbinfo->notnull_islocal) || + !tbinfo->notnull_islocal[j]) || !PQgetisnull(res, r, i_notnull_comment)) { tbinfo->notnull_constrs[j] = [parent: 3eb2fecdbbfc]