On 07.07.23 03:03, Paul A Jungwirth wrote:
Here are some new patch files based on discussions from PGCon.
Here are a few fixup patches to get things building without warnings and errors.
The last patch (your 0005) fails the regression test for me and it didn't appear to be a trivial problem, so please take another look at that sometime. (Since it's the last patch, it's obviously lower priority.)
From 6694912b0fdd8742e583ff2a524f32284c330711 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut <pe...@eisentraut.org> Date: Wed, 12 Jul 2023 09:45:56 +0200 Subject: [PATCH v12] fixup! Add temporal PRIMARY KEY and UNIQUE constraints --- src/bin/pg_dump/pg_dump.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index a95e1d3696..33ad34ad66 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -7029,16 +7029,14 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) "(SELECT pg_catalog.array_agg(attstattarget ORDER BY attnum) " " FROM pg_catalog.pg_attribute " " WHERE attrelid = i.indexrelid AND " - " attstattarget >= 0) AS indstatvals, " - "c.conexclop IS NOT NULL AS withoutoverlaps, "); + " attstattarget >= 0) AS indstatvals, "); else appendPQExpBufferStr(query, "0 AS parentidx, " "i.indnatts AS indnkeyatts, " "i.indnatts AS indnatts, " "'' AS indstatcols, " - "'' AS indstatvals, " - "null AS withoutoverlaps, "); + "'' AS indstatvals, "); if (fout->remoteVersion >= 150000) appendPQExpBufferStr(query, @@ -7047,6 +7045,13 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) appendPQExpBufferStr(query, "false AS indnullsnotdistinct, "); + if (fout->remoteVersion >= 170000) + appendPQExpBufferStr(query, + "c.conexclop IS NOT NULL AS withoutoverlaps "); + else + appendPQExpBufferStr(query, + "null AS withoutoverlaps "); + /* * The point of the messy-looking outer join is to find a constraint that * is related by an internal dependency link to the index. If we find one, -- 2.41.0
From 49932adb8e626036b8d8edf26ed1465f39db82bd Mon Sep 17 00:00:00 2001 From: Peter Eisentraut <pe...@eisentraut.org> Date: Wed, 12 Jul 2023 10:16:53 +0200 Subject: [PATCH v12] fixup! Add UPDATE/DELETE FOR PORTION OF --- doc/src/sgml/ref/delete.sgml | 2 ++ doc/src/sgml/ref/update.sgml | 2 ++ src/backend/parser/analyze.c | 5 +++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/doc/src/sgml/ref/delete.sgml b/doc/src/sgml/ref/delete.sgml index 868cf0d1f9..aec593239b 100644 --- a/doc/src/sgml/ref/delete.sgml +++ b/doc/src/sgml/ref/delete.sgml @@ -55,6 +55,7 @@ <title>Description</title> circumstances. </para> + <!-- FIXME <para> If the table has a <link linkend="ddl-periods-application-periods">temporal primary key</link>, you may supply a @@ -63,6 +64,7 @@ <title>Description</title> the <literal>FOR PORTION OF</literal> bounds, then new rows spanning the "cut off" duration will be inserted to preserve the old values. </para> + --> <para> The optional <literal>RETURNING</literal> clause causes <command>DELETE</command> diff --git a/doc/src/sgml/ref/update.sgml b/doc/src/sgml/ref/update.sgml index f2042e0b25..62e9e0e1f0 100644 --- a/doc/src/sgml/ref/update.sgml +++ b/doc/src/sgml/ref/update.sgml @@ -52,6 +52,7 @@ <title>Description</title> circumstances. </para> + <!-- FIXME <para> If the table has a <link linkend="ddl-periods-application-periods">temporal primary key</link>, you may supply a @@ -61,6 +62,7 @@ <title>Description</title> within the bounds, and new rows spanning the "cut off" duration will be inserted to preserve the old values. </para> + --> <para> The optional <literal>RETURNING</literal> clause causes <command>UPDATE</command> diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 0b2109d1bb..c6d2b7e1d1 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -1247,6 +1247,7 @@ transformForPortionOfClause(ParseState *pstate, char *range_name = forPortionOf->range_name; char *range_type_name = NULL; int range_attno = InvalidAttrNumber; + Form_pg_attribute attr; ForPortionOfExpr *result; List *targetList; Node *target_start, *target_end; @@ -1264,7 +1265,7 @@ transformForPortionOfClause(ParseState *pstate, range_name, RelationGetRelationName(targetrel)), parser_errposition(pstate, forPortionOf->range_name_location))); - Form_pg_attribute attr = TupleDescAttr(targetrel->rd_att, range_attno - 1); + attr = TupleDescAttr(targetrel->rd_att, range_attno - 1); // TODO: check attr->attisdropped (?), // and figure out concurrency issues with that in general. // It should work the same as updating any other column. @@ -1317,12 +1318,12 @@ transformForPortionOfClause(ParseState *pstate, * Now make sure we update the start/end time of the record. * For a range col (r) this is `r = r * targetRange`. */ - targetList = NIL; Expr *rangeSetExpr = (Expr *) makeSimpleA_Expr(AEXPR_OP, "*", (Node *) copyObject(rangeVar), (Node *) fc, forPortionOf->range_name_location); TargetEntry *tle; + targetList = NIL; rangeSetExpr = (Expr *) transformExpr(pstate, (Node *) rangeSetExpr, EXPR_KIND_UPDATE_PORTION); tle = makeTargetEntry(rangeSetExpr, range_attno, -- 2.41.0
From a831c9d79bb979a1360e90db00adddb156dd582a Mon Sep 17 00:00:00 2001 From: Peter Eisentraut <pe...@eisentraut.org> Date: Wed, 12 Jul 2023 10:13:01 +0200 Subject: [PATCH v12] fixup! Add PERIODs --- doc/src/sgml/ref/alter_table.sgml | 2 +- src/backend/catalog/heap.c | 3 ++- src/backend/catalog/meson.build | 1 + src/backend/commands/tablecmds.c | 3 ++- src/include/catalog/meson.build | 1 + src/test/modules/test_ddl_deparse/test_ddl_deparse.c | 6 ++++++ 6 files changed, 13 insertions(+), 3 deletions(-) diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml index 487f09f88a..d6aed3dff8 100644 --- a/doc/src/sgml/ref/alter_table.sgml +++ b/doc/src/sgml/ref/alter_table.sgml @@ -582,7 +582,7 @@ <title>Description</title> </listitem> </varlistentry> - <varlistentry> + <varlistentry id="sql-altertable-desc-drop-period"> <term><literal>DROP PERIOD FOR</literal></term> <listitem> <para> diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 022a2ede4c..a31c22c6b7 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -2062,7 +2062,6 @@ Oid StorePeriod(Relation rel, const char *periodname, AttrNumber startnum, AttrNumber endnum, AttrNumber rangenum, Oid conoid) { - Assert(rangenum != InvalidAttrNumber); Datum values[Natts_pg_period]; bool nulls[Natts_pg_period]; Relation pg_period; @@ -2071,6 +2070,8 @@ StorePeriod(Relation rel, const char *periodname, AttrNumber startnum, NameData pername; ObjectAddress myself, referenced; + Assert(rangenum != InvalidAttrNumber); + namestrcpy(&pername, periodname); MemSet(values, 0, sizeof(values)); diff --git a/src/backend/catalog/meson.build b/src/backend/catalog/meson.build index fa6609e577..c499cd2f5d 100644 --- a/src/backend/catalog/meson.build +++ b/src/backend/catalog/meson.build @@ -26,6 +26,7 @@ backend_sources += files( 'pg_namespace.c', 'pg_operator.c', 'pg_parameter_acl.c', + 'pg_period.c', 'pg_proc.c', 'pg_publication.c', 'pg_range.c', diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index ef17b3e31e..d95f742b29 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8384,6 +8384,7 @@ ATExecAddPeriod(Relation rel, PeriodDef *period, AlterTableUtilityContext *conte Relation attrelation; ObjectAddress address = InvalidObjectAddress; Constraint *constr; + ColumnDef *rangecol; Oid conoid, periodoid; List *cmds = NIL; AlterTableCmd *cmd; @@ -8418,7 +8419,7 @@ ATExecAddPeriod(Relation rel, PeriodDef *period, AlterTableUtilityContext *conte conoid = get_relation_constraint_oid(RelationGetRelid(rel), period->constraintname, false); /* Make the range column */ - ColumnDef *rangecol = make_range_column_for_period(period); + rangecol = make_range_column_for_period(period); cmd = makeNode(AlterTableCmd); cmd->subtype = AT_AddColumn; cmd->def = (Node *) rangecol; diff --git a/src/include/catalog/meson.build b/src/include/catalog/meson.build index c3fd05d027..158496d19d 100644 --- a/src/include/catalog/meson.build +++ b/src/include/catalog/meson.build @@ -57,6 +57,7 @@ catalog_headers = [ 'pg_collation.h', 'pg_parameter_acl.h', 'pg_partitioned_table.h', + 'pg_period.h', 'pg_range.h', 'pg_transform.h', 'pg_sequence.h', diff --git a/src/test/modules/test_ddl_deparse/test_ddl_deparse.c b/src/test/modules/test_ddl_deparse/test_ddl_deparse.c index 82f937fca4..2436996b1c 100644 --- a/src/test/modules/test_ddl_deparse/test_ddl_deparse.c +++ b/src/test/modules/test_ddl_deparse/test_ddl_deparse.c @@ -180,6 +180,12 @@ get_altertable_subcmdinfo(PG_FUNCTION_ARGS) case AT_DropConstraint: strtype = "DROP CONSTRAINT"; break; + case AT_AddPeriod: + strtype = "ADD PERIOD"; + break; + case AT_DropPeriod: + strtype = "DROP PERIOD"; + break; case AT_ReAddComment: strtype = "(re) ADD COMMENT"; break; -- 2.41.0