From 76249c9a64caaaf4c3206d5ca4ff72cc186dc416 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 6 Feb 2020 14:50:01 +0100 Subject: [PATCH v3] pg_dump: Fix dumping of inherited generated columns Generation expressions of generated columns are always inherited, so there is no need to set them separately in child tables, and there is no syntax to do so either. The code previously used the code paths for the handling of default values, for which different rules apply; in particular it might want to set a default value explicitly for an inherited column. For generated columns, just skip all that. Discussion: https://www.postgresql.org/message-id/flat/15830.1575468847%40sss.pgh.pa.us --- src/bin/pg_dump/common.c | 8 ++++++++ src/bin/pg_dump/pg_dump.c | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/src/bin/pg_dump/common.c b/src/bin/pg_dump/common.c index 3549f7bc08..170c87823d 100644 --- a/src/bin/pg_dump/common.c +++ b/src/bin/pg_dump/common.c @@ -476,6 +476,14 @@ flagInhAttrs(DumpOptions *dopt, TableInfo *tblinfo, int numTables) if (tbinfo->attisdropped[j]) continue; + /* + * Skip generated columns; it is not possible for an inherited + * column to have a different generation expression that the + * parent. + */ + if (tbinfo->attgenerated[j]) + continue; + foundNotNull = false; foundDefault = false; for (k = 0; k < numParents; k++) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 33e58fa287..5fcb89093e 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -8492,6 +8492,15 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) if (tbinfo->attisdropped[adnum - 1]) continue; + /* + * Ignore generated columns on child tables unless they have a + * local definition. Generation expressions are always + * inherited, so there is no need to set them again in child + * tables, and there is no syntax for it either. + */ + if (tbinfo->attgenerated[adnum - 1] && !tbinfo->attislocal[adnum - 1]) + continue; + attrdefs[j].dobj.objType = DO_ATTRDEF; attrdefs[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, 0)); attrdefs[j].dobj.catId.oid = atooid(PQgetvalue(res, j, 1)); -- 2.25.0