Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 79b575d

Browse files
committed
Fix ALTER TABLE / REPLICA IDENTITY for temporal tables
REPLICA IDENTITY USING INDEX did not accept a GiST index. This should be allowed when used as a temporal primary key. Author: Paul Jungwirth <pj@illuminatedcomputing.com> Discussion: https://www.postgresql.org/message-id/04579cbf-b134-45e1-8f2d-8c54c849c1ee@illuminatedcomputing.com
1 parent da94e87 commit 79b575d

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

src/backend/commands/tablecmds.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -17296,9 +17296,14 @@ ATExecReplicaIdentity(Relation rel, ReplicaIdentityStmt *stmt, LOCKMODE lockmode
1729617296
errmsg("\"%s\" is not an index for table \"%s\"",
1729717297
RelationGetRelationName(indexRel),
1729817298
RelationGetRelationName(rel))));
17299-
/* The AM must support uniqueness, and the index must in fact be unique. */
17300-
if (!indexRel->rd_indam->amcanunique ||
17301-
!indexRel->rd_index->indisunique)
17299+
/*
17300+
* The AM must support uniqueness, and the index must in fact be unique.
17301+
* If we have a WITHOUT OVERLAPS constraint (identified by uniqueness +
17302+
* exclusion), we can use that too.
17303+
*/
17304+
if ((!indexRel->rd_indam->amcanunique ||
17305+
!indexRel->rd_index->indisunique) &&
17306+
!(indexRel->rd_index->indisunique && indexRel->rd_index->indisexclusion))
1730217307
ereport(ERROR,
1730317308
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
1730417309
errmsg("cannot use non-unique index \"%s\" as replica identity",

src/test/regress/expected/without_overlaps.out

+18-2
Original file line numberDiff line numberDiff line change
@@ -978,9 +978,25 @@ SELECT * FROM tp2 ORDER BY id, valid_at;
978978

979979
DROP TABLE temporal_partitioned;
980980
-- ALTER TABLE REPLICA IDENTITY
981-
-- (should fail)
981+
\d temporal_rng
982+
Table "public.temporal_rng"
983+
Column | Type | Collation | Nullable | Default
984+
----------+-----------+-----------+----------+---------
985+
id | int4range | | not null |
986+
valid_at | daterange | | not null |
987+
Indexes:
988+
"temporal_rng_pk" PRIMARY KEY (id, valid_at WITHOUT OVERLAPS)
989+
982990
ALTER TABLE temporal_rng REPLICA IDENTITY USING INDEX temporal_rng_pk;
983-
ERROR: cannot use non-unique index "temporal_rng_pk" as replica identity
991+
\d temporal_rng
992+
Table "public.temporal_rng"
993+
Column | Type | Collation | Nullable | Default
994+
----------+-----------+-----------+----------+---------
995+
id | int4range | | not null |
996+
valid_at | daterange | | not null |
997+
Indexes:
998+
"temporal_rng_pk" PRIMARY KEY (id, valid_at WITHOUT OVERLAPS) REPLICA IDENTITY
999+
9841000
--
9851001
-- ON CONFLICT: ranges
9861002
--

src/test/regress/sql/without_overlaps.sql

+2-1
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,9 @@ SELECT * FROM tp2 ORDER BY id, valid_at;
691691
DROP TABLE temporal_partitioned;
692692

693693
-- ALTER TABLE REPLICA IDENTITY
694-
-- (should fail)
694+
\d temporal_rng
695695
ALTER TABLE temporal_rng REPLICA IDENTITY USING INDEX temporal_rng_pk;
696+
\d temporal_rng
696697

697698
--
698699
-- ON CONFLICT: ranges

0 commit comments

Comments
 (0)