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

Commit 005ac29

Browse files
committed
Prohibit identity columns on typed tables and partitions
Those cases currently crash and supporting them is more work then originally thought, so we'll just prohibit these scenarios for now. Author: Michael Paquier <michael.paquier@gmail.com> Reviewed-by: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp> Reported-by: Мансур Галиев <gomer94@yandex.ru> Bug: #14866
1 parent af9f8b7 commit 005ac29

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

src/backend/parser/parse_utilcmd.c

+13
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ typedef struct
9292
IndexStmt *pkey; /* PRIMARY KEY index, if any */
9393
bool ispartitioned; /* true if table is partitioned */
9494
PartitionBoundSpec *partbound; /* transformed FOR VALUES */
95+
bool ofType; /* true if statement contains OF typename */
9596
} CreateStmtContext;
9697

9798
/* State shared by transformCreateSchemaStmt and its subroutines */
@@ -240,6 +241,8 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)
240241
cxt.alist = NIL;
241242
cxt.pkey = NULL;
242243
cxt.ispartitioned = stmt->partspec != NULL;
244+
cxt.partbound = stmt->partbound;
245+
cxt.ofType = (stmt->ofTypename != NULL);
243246

244247
/*
245248
* Notice that we allow OIDs here only for plain tables, even though
@@ -662,6 +665,15 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
662665
Type ctype;
663666
Oid typeOid;
664667

668+
if (cxt->ofType)
669+
ereport(ERROR,
670+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
671+
errmsg("identity colums are not supported on typed tables")));
672+
if (cxt->partbound)
673+
ereport(ERROR,
674+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
675+
errmsg("identify columns are not supported on partitions")));
676+
665677
ctype = typenameType(cxt->pstate, column->typeName, NULL);
666678
typeOid = HeapTupleGetOid(ctype);
667679
ReleaseSysCache(ctype);
@@ -2697,6 +2709,7 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
26972709
cxt.pkey = NULL;
26982710
cxt.ispartitioned = (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
26992711
cxt.partbound = NULL;
2712+
cxt.ofType = false;
27002713

27012714
/*
27022715
* The only subtypes that currently require parse transformation handling

src/test/regress/expected/identity.out

+12
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,15 @@ SELECT * FROM itest8;
346346
RESET ROLE;
347347
DROP TABLE itest8;
348348
DROP USER regress_user1;
349+
-- typed tables (currently not supported)
350+
CREATE TYPE itest_type AS (f1 integer, f2 text, f3 bigint);
351+
CREATE TABLE itest12 OF itest_type (f1 WITH OPTIONS GENERATED ALWAYS AS IDENTITY); -- error
352+
ERROR: identity colums are not supported on typed tables
353+
DROP TYPE itest_type CASCADE;
354+
-- table partitions (currently not supported)
355+
CREATE TABLE itest_parent (f1 date NOT NULL, f2 text, f3 bigint) PARTITION BY RANGE (f1);
356+
CREATE TABLE itest_child PARTITION OF itest_parent (
357+
f3 WITH OPTIONS GENERATED ALWAYS AS IDENTITY
358+
) FOR VALUES FROM ('2016-07-01') TO ('2016-08-01'); -- error
359+
ERROR: identify columns are not supported on partitions
360+
DROP TABLE itest_parent;

src/test/regress/sql/identity.sql

+16
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,19 @@ SELECT * FROM itest8;
211211
RESET ROLE;
212212
DROP TABLE itest8;
213213
DROP USER regress_user1;
214+
215+
216+
-- typed tables (currently not supported)
217+
218+
CREATE TYPE itest_type AS (f1 integer, f2 text, f3 bigint);
219+
CREATE TABLE itest12 OF itest_type (f1 WITH OPTIONS GENERATED ALWAYS AS IDENTITY); -- error
220+
DROP TYPE itest_type CASCADE;
221+
222+
223+
-- table partitions (currently not supported)
224+
225+
CREATE TABLE itest_parent (f1 date NOT NULL, f2 text, f3 bigint) PARTITION BY RANGE (f1);
226+
CREATE TABLE itest_child PARTITION OF itest_parent (
227+
f3 WITH OPTIONS GENERATED ALWAYS AS IDENTITY
228+
) FOR VALUES FROM ('2016-07-01') TO ('2016-08-01'); -- error
229+
DROP TABLE itest_parent;

0 commit comments

Comments
 (0)