Skip to content

Commit 6de3b27

Browse files
author
Commitfest Bot
committed
[CF 4308] v49 - SQL:2011 application time
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/4308 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/[email protected] Author(s): Paul Jungwirth
2 parents 9e088f7 + a69edc7 commit 6de3b27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+7179
-204
lines changed

contrib/bloom/blvalidate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ blvalidate(Oid opclassoid)
9696
switch (procform->amprocnum)
9797
{
9898
case BLOOM_HASH_PROC:
99-
ok = check_amproc_signature(procform->amproc, INT4OID, false,
99+
ok = check_amproc_signature(procform->amproc, INT4OID, false, false,
100100
1, 1, opckeytype);
101101
break;
102102
case BLOOM_OPTIONS_PROC:

contrib/postgres_fdw/expected/postgres_fdw.out

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,19 @@ CREATE TABLE "S 1"."T 4" (
5757
c3 text,
5858
CONSTRAINT t4_pkey PRIMARY KEY (c1)
5959
);
60+
CREATE TABLE "S 1"."T 5" (
61+
c1 int4range NOT NULL,
62+
c2 int NOT NULL,
63+
c3 text,
64+
c4 daterange NOT NULL,
65+
CONSTRAINT t5_pkey PRIMARY KEY (c1, c4 WITHOUT OVERLAPS)
66+
);
6067
-- Disable autovacuum for these tables to avoid unexpected effects of that
6168
ALTER TABLE "S 1"."T 1" SET (autovacuum_enabled = 'false');
6269
ALTER TABLE "S 1"."T 2" SET (autovacuum_enabled = 'false');
6370
ALTER TABLE "S 1"."T 3" SET (autovacuum_enabled = 'false');
6471
ALTER TABLE "S 1"."T 4" SET (autovacuum_enabled = 'false');
72+
ALTER TABLE "S 1"."T 5" SET (autovacuum_enabled = 'false');
6573
INSERT INTO "S 1"."T 1"
6674
SELECT id,
6775
id % 10,
@@ -88,10 +96,17 @@ INSERT INTO "S 1"."T 4"
8896
'AAA' || to_char(id, 'FM000')
8997
FROM generate_series(1, 100) id;
9098
DELETE FROM "S 1"."T 4" WHERE c1 % 3 != 0; -- delete for outer join tests
99+
INSERT INTO "S 1"."T 5"
100+
SELECT int4range(id, id + 1),
101+
id + 1,
102+
'AAA' || to_char(id, 'FM000'),
103+
'[2000-01-01,2020-01-01)'
104+
FROM generate_series(1, 100) id;
91105
ANALYZE "S 1"."T 1";
92106
ANALYZE "S 1"."T 2";
93107
ANALYZE "S 1"."T 3";
94108
ANALYZE "S 1"."T 4";
109+
ANALYZE "S 1"."T 5";
95110
-- ===================================================================
96111
-- create foreign tables
97112
-- ===================================================================
@@ -139,6 +154,12 @@ CREATE FOREIGN TABLE ft7 (
139154
c2 int NOT NULL,
140155
c3 text
141156
) SERVER loopback3 OPTIONS (schema_name 'S 1', table_name 'T 4');
157+
CREATE FOREIGN TABLE ft8 (
158+
c1 int4range NOT NULL,
159+
c2 int NOT NULL,
160+
c3 text,
161+
c4 daterange NOT NULL
162+
) SERVER loopback OPTIONS (schema_name 'S 1', table_name 'T 5');
142163
-- ===================================================================
143164
-- tests for validator
144165
-- ===================================================================
@@ -210,7 +231,8 @@ ALTER FOREIGN TABLE ft2 ALTER COLUMN c1 OPTIONS (column_name 'C 1');
210231
public | ft5 | loopback | (schema_name 'S 1', table_name 'T 4') |
211232
public | ft6 | loopback2 | (schema_name 'S 1', table_name 'T 4') |
212233
public | ft7 | loopback3 | (schema_name 'S 1', table_name 'T 4') |
213-
(6 rows)
234+
public | ft8 | loopback | (schema_name 'S 1', table_name 'T 5') |
235+
(7 rows)
214236

215237
-- Test that alteration of server options causes reconnection
216238
-- Remote's errors might be non-English, so hide them to ensure stable results
@@ -6176,6 +6198,27 @@ DELETE FROM ft2 WHERE c1 = 1200 RETURNING tableoid::regclass;
61766198
ft2
61776199
(1 row)
61786200

6201+
-- Test UPDATE FOR PORTION OF
6202+
UPDATE ft8 FOR PORTION OF c4 FROM '2005-01-01' TO '2006-01-01'
6203+
SET c2 = c2 + 1
6204+
WHERE c1 = '[1,2)';
6205+
ERROR: foreign tables don't support FOR PORTION OF
6206+
SELECT * FROM ft8 WHERE c1 = '[1,2)' ORDER BY c1, c4;
6207+
c1 | c2 | c3 | c4
6208+
-------+----+--------+-------------------------
6209+
[1,2) | 2 | AAA001 | [01-01-2000,01-01-2020)
6210+
(1 row)
6211+
6212+
-- Test DELETE FOR PORTION OF
6213+
DELETE FROM ft8 FOR PORTION OF c4 FROM '2005-01-01' TO '2006-01-01'
6214+
WHERE c1 = '[2,3)';
6215+
ERROR: foreign tables don't support FOR PORTION OF
6216+
SELECT * FROM ft8 WHERE c1 = '[2,3)' ORDER BY c1, c4;
6217+
c1 | c2 | c3 | c4
6218+
-------+----+--------+-------------------------
6219+
[2,3) | 3 | AAA002 | [01-01-2000,01-01-2020)
6220+
(1 row)
6221+
61796222
-- Test UPDATE/DELETE with RETURNING on a three-table join
61806223
INSERT INTO ft2 (c1,c2,c3)
61816224
SELECT id, id - 1200, to_char(id, 'FM00000') FROM generate_series(1201, 1300) id;

contrib/postgres_fdw/sql/postgres_fdw.sql

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,20 @@ CREATE TABLE "S 1"."T 4" (
6161
c3 text,
6262
CONSTRAINT t4_pkey PRIMARY KEY (c1)
6363
);
64+
CREATE TABLE "S 1"."T 5" (
65+
c1 int4range NOT NULL,
66+
c2 int NOT NULL,
67+
c3 text,
68+
c4 daterange NOT NULL,
69+
CONSTRAINT t5_pkey PRIMARY KEY (c1, c4 WITHOUT OVERLAPS)
70+
);
6471

6572
-- Disable autovacuum for these tables to avoid unexpected effects of that
6673
ALTER TABLE "S 1"."T 1" SET (autovacuum_enabled = 'false');
6774
ALTER TABLE "S 1"."T 2" SET (autovacuum_enabled = 'false');
6875
ALTER TABLE "S 1"."T 3" SET (autovacuum_enabled = 'false');
6976
ALTER TABLE "S 1"."T 4" SET (autovacuum_enabled = 'false');
77+
ALTER TABLE "S 1"."T 5" SET (autovacuum_enabled = 'false');
7078

7179
INSERT INTO "S 1"."T 1"
7280
SELECT id,
@@ -94,11 +102,18 @@ INSERT INTO "S 1"."T 4"
94102
'AAA' || to_char(id, 'FM000')
95103
FROM generate_series(1, 100) id;
96104
DELETE FROM "S 1"."T 4" WHERE c1 % 3 != 0; -- delete for outer join tests
105+
INSERT INTO "S 1"."T 5"
106+
SELECT int4range(id, id + 1),
107+
id + 1,
108+
'AAA' || to_char(id, 'FM000'),
109+
'[2000-01-01,2020-01-01)'
110+
FROM generate_series(1, 100) id;
97111

98112
ANALYZE "S 1"."T 1";
99113
ANALYZE "S 1"."T 2";
100114
ANALYZE "S 1"."T 3";
101115
ANALYZE "S 1"."T 4";
116+
ANALYZE "S 1"."T 5";
102117

103118
-- ===================================================================
104119
-- create foreign tables
@@ -153,6 +168,14 @@ CREATE FOREIGN TABLE ft7 (
153168
c3 text
154169
) SERVER loopback3 OPTIONS (schema_name 'S 1', table_name 'T 4');
155170

171+
CREATE FOREIGN TABLE ft8 (
172+
c1 int4range NOT NULL,
173+
c2 int NOT NULL,
174+
c3 text,
175+
c4 daterange NOT NULL
176+
) SERVER loopback OPTIONS (schema_name 'S 1', table_name 'T 5');
177+
178+
156179
-- ===================================================================
157180
-- tests for validator
158181
-- ===================================================================
@@ -1511,6 +1534,17 @@ EXPLAIN (verbose, costs off)
15111534
DELETE FROM ft2 WHERE c1 = 1200 RETURNING tableoid::regclass; -- can be pushed down
15121535
DELETE FROM ft2 WHERE c1 = 1200 RETURNING tableoid::regclass;
15131536

1537+
-- Test UPDATE FOR PORTION OF
1538+
UPDATE ft8 FOR PORTION OF c4 FROM '2005-01-01' TO '2006-01-01'
1539+
SET c2 = c2 + 1
1540+
WHERE c1 = '[1,2)';
1541+
SELECT * FROM ft8 WHERE c1 = '[1,2)' ORDER BY c1, c4;
1542+
1543+
-- Test DELETE FOR PORTION OF
1544+
DELETE FROM ft8 FOR PORTION OF c4 FROM '2005-01-01' TO '2006-01-01'
1545+
WHERE c1 = '[2,3)';
1546+
SELECT * FROM ft8 WHERE c1 = '[2,3)' ORDER BY c1, c4;
1547+
15141548
-- Test UPDATE/DELETE with RETURNING on a three-table join
15151549
INSERT INTO ft2 (c1,c2,c3)
15161550
SELECT id, id - 1200, to_char(id, 'FM00000') FROM generate_series(1201, 1300) id;

contrib/sepgsql/proc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ sepgsql_proc_drop(Oid functionId)
161161
* check db_schema:{remove_name} permission
162162
*/
163163
object.classId = NamespaceRelationId;
164-
object.objectId = get_func_namespace(functionId);
164+
object.objectId = get_func_namespace(functionId, true);
165165
object.objectSubId = 0;
166166
audit_name = getObjectIdentity(&object, false);
167167

doc/src/sgml/gist.sgml

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ CREATE INDEX ON my_table USING GIST (my_inet_column inet_ops);
266266

267267
<para>
268268
There are five methods that an index operator class for
269-
<acronym>GiST</acronym> must provide, and seven that are optional.
269+
<acronym>GiST</acronym> must provide, and eight that are optional.
270270
Correctness of the index is ensured
271271
by proper implementation of the <function>same</function>, <function>consistent</function>
272272
and <function>union</function> methods, while efficiency (size and speed) of the
@@ -294,6 +294,9 @@ CREATE INDEX ON my_table USING GIST (my_inet_column inet_ops);
294294
<filename>src/include/nodes/primnodes.h</filename>) into strategy numbers
295295
used by the operator class. This lets the core code look up operators for
296296
temporal constraint indexes.
297+
The optional thirteenth method <function>without_portion</function> is used by
298+
<literal>RESTRICT</literal> foreign keys to compute the portion of history
299+
that was lost.
297300
</para>
298301

299302
<variablelist>
@@ -1241,6 +1244,108 @@ my_stratnum(PG_FUNCTION_ARGS)
12411244
</para>
12421245
</listitem>
12431246
</varlistentry>
1247+
<varlistentry>
1248+
<term><function>without_portion</function></term>
1249+
<listitem>
1250+
<para>
1251+
Given two values of this opclass, it subtracts the second for the first
1252+
and returns an array of the results.
1253+
</para>
1254+
<para>
1255+
This is used by temporal foreign keys to compute the part
1256+
of history that was lost by an update.
1257+
</para>
1258+
1259+
<para>
1260+
The <acronym>SQL</acronym> declaration of the function must look like
1261+
this (using <literal>my_range_without_portion</literal> as an example):
1262+
1263+
<programlisting>
1264+
CREATE OR REPLACE FUNCTION my_range_without_portion(anyrange, anyrange)
1265+
RETURNS anyarray
1266+
AS 'MODULE_PATHNAME'
1267+
LANGUAGE C STRICT;
1268+
</programlisting>
1269+
</para>
1270+
1271+
<para>
1272+
The matching code in the C module could then follow this example:
1273+
1274+
<programlisting>
1275+
Datum
1276+
my_range_without_portion(PG_FUNCTION_ARGS)
1277+
{
1278+
typedef struct {
1279+
RangeType *rs[2];
1280+
int n;
1281+
} range_without_portion_fctx;
1282+
1283+
FuncCallContext *funcctx;
1284+
range_without_portion_fctx *fctx;
1285+
MemoryContext oldcontext;
1286+
1287+
/* stuff done only on the first call of the function */
1288+
if (SRF_IS_FIRSTCALL())
1289+
{
1290+
RangeType *r1;
1291+
RangeType *r2;
1292+
Oid rngtypid;
1293+
TypeCacheEntry *typcache;
1294+
1295+
/* create a function context for cross-call persistence */
1296+
funcctx = SRF_FIRSTCALL_INIT();
1297+
1298+
/*
1299+
* switch to memory context appropriate for multiple function calls
1300+
*/
1301+
oldcontext = MemoryContextSwitchTo(funcctx-&gt;multi_call_memory_ctx);
1302+
1303+
r1 = PG_GETARG_RANGE_P(0);
1304+
r2 = PG_GETARG_RANGE_P(1);
1305+
1306+
/* Different types should be prevented by ANYRANGE matching rules */
1307+
if (RangeTypeGetOid(r1) != RangeTypeGetOid(r2))
1308+
elog(ERROR, "range types do not match");
1309+
1310+
/* allocate memory for user context */
1311+
fctx = (range_without_portion_fctx *) palloc(sizeof(range_without_portion_fctx));
1312+
1313+
/*
1314+
* Initialize state.
1315+
* We can't store the range typcache in fn_extra because the caller
1316+
* uses that for the SRF state.
1317+
*/
1318+
rngtypid = RangeTypeGetOid(r1);
1319+
typcache = lookup_type_cache(rngtypid, TYPECACHE_RANGE_INFO);
1320+
if (typcache-&gt;rngelemtype == NULL)
1321+
elog(ERROR, "type %u is not a range type", rngtypid);
1322+
range_without_portion_internal(typcache, r1, r2, fctx-&gt;rs, &amp;fctx-&gt;n);
1323+
1324+
funcctx-&gt;user_fctx = fctx;
1325+
MemoryContextSwitchTo(oldcontext);
1326+
}
1327+
1328+
/* stuff done on every call of the function */
1329+
funcctx = SRF_PERCALL_SETUP();
1330+
fctx = funcctx-&gt;user_fctx;
1331+
1332+
if (funcctx-&gt;call_cntr &lt; fctx-&gt;n)
1333+
{
1334+
/*
1335+
* We must keep these on separate lines
1336+
* because SRF_RETURN_NEXT does call_cntr++:
1337+
*/
1338+
RangeType *ret = fctx-&gt;rs[funcctx-&gt;call_cntr];
1339+
SRF_RETURN_NEXT(funcctx, RangeTypePGetDatum(ret));
1340+
}
1341+
else
1342+
/* do when there is no more left */
1343+
SRF_RETURN_DONE(funcctx);
1344+
}
1345+
</programlisting>
1346+
</para>
1347+
</listitem>
1348+
</varlistentry>
12441349
</variablelist>
12451350

12461351
<para>

doc/src/sgml/plpgsql.sgml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4247,6 +4247,30 @@ ASSERT <replaceable class="parameter">condition</replaceable> <optional> , <repl
42474247
</para>
42484248
</listitem>
42494249
</varlistentry>
4250+
4251+
<varlistentry id="plpgsql-dml-trigger-tg-temporal-column">
4252+
<term><varname>TG_PERIOD_NAME</varname> <type>text</type></term>
4253+
<listitem>
4254+
<para>
4255+
the column name used in a <literal>FOR PORTION OF</literal> clause,
4256+
or else <symbol>NULL</symbol>.
4257+
</para>
4258+
</listitem>
4259+
</varlistentry>
4260+
4261+
<varlistentry id="plpgsql-dml-trigger-tg-temporal-target">
4262+
<term><varname>TG_PERIOD_BOUNDS</varname> <type>text</type></term>
4263+
<listitem>
4264+
<para>
4265+
the range/multirange/etc. given as the bounds of a
4266+
<literal>FOR PORTION OF</literal> clause, either directly (with parens syntax)
4267+
or computed from the <literal>FROM</literal> and <literal>TO</literal> bounds.
4268+
<symbol>NULL</symbol> if <literal>FOR PORTION OF</literal> was not used.
4269+
This is a text value based on the type's output function,
4270+
since the type can't be known at function creation time.
4271+
</para>
4272+
</listitem>
4273+
</varlistentry>
42504274
</variablelist>
42514275
</para>
42524276

doc/src/sgml/ref/create_publication.sgml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,12 @@ CREATE PUBLICATION <replaceable class="parameter">name</replaceable>
367367
for each row inserted, updated, or deleted.
368368
</para>
369369

370+
<para>
371+
For a <command>FOR PORTION OF</command> command, the publication will publish an
372+
<command>UPDATE</command> or <command>DELETE</command>, followed by one
373+
<command>INSERT</command> for each leftover row inserted.
374+
</para>
375+
370376
<para>
371377
<command>ATTACH</command>ing a table into a partition tree whose root is
372378
published using a publication with <literal>publish_via_partition_root</literal>

doc/src/sgml/ref/create_table.sgml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,9 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
12991299
</para>
13001300

13011301
<para>
1302-
In a temporal foreign key, this option is not supported.
1302+
In a temporal foreign key, the delete/update will use
1303+
<literal>FOR PORTION OF</literal> semantics to constrain the
1304+
effect to the bounds being deleted/updated in the referenced row.
13031305
</para>
13041306
</listitem>
13051307
</varlistentry>
@@ -1314,7 +1316,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
13141316
</para>
13151317

13161318
<para>
1317-
In a temporal foreign key, this option is not supported.
1319+
In a temporal foreign key, the change will use <literal>FOR PORTION
1320+
OF</literal> semantics to constrain the effect to the bounds being
1321+
deleted/updated in the referenced row. The column maked with
1322+
<literal>PERIOD</literal> will not be set to null.
13181323
</para>
13191324
</listitem>
13201325
</varlistentry>
@@ -1331,7 +1336,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
13311336
</para>
13321337

13331338
<para>
1334-
In a temporal foreign key, this option is not supported.
1339+
In a temporal foreign key, the change will use <literal>FOR PORTION
1340+
OF</literal> semantics to constrain the effect to the bounds being
1341+
deleted/updated in the referenced row. The column marked with
1342+
<literal>PERIOD</literal> with not be set to a default value.
13351343
</para>
13361344
</listitem>
13371345
</varlistentry>

0 commit comments

Comments
 (0)