Commit 005ac298 authored by Peter Eisentraut's avatar Peter Eisentraut

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: default avatarAmit Langote <Langote_Amit_f8@lab.ntt.co.jp>
Reported-by: default avatarМансур Галиев <gomer94@yandex.ru>
Bug: #14866
parent af9f8b7c
...@@ -92,6 +92,7 @@ typedef struct ...@@ -92,6 +92,7 @@ typedef struct
IndexStmt *pkey; /* PRIMARY KEY index, if any */ IndexStmt *pkey; /* PRIMARY KEY index, if any */
bool ispartitioned; /* true if table is partitioned */ bool ispartitioned; /* true if table is partitioned */
PartitionBoundSpec *partbound; /* transformed FOR VALUES */ PartitionBoundSpec *partbound; /* transformed FOR VALUES */
bool ofType; /* true if statement contains OF typename */
} CreateStmtContext; } CreateStmtContext;
/* State shared by transformCreateSchemaStmt and its subroutines */ /* State shared by transformCreateSchemaStmt and its subroutines */
...@@ -240,6 +241,8 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString) ...@@ -240,6 +241,8 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)
cxt.alist = NIL; cxt.alist = NIL;
cxt.pkey = NULL; cxt.pkey = NULL;
cxt.ispartitioned = stmt->partspec != NULL; cxt.ispartitioned = stmt->partspec != NULL;
cxt.partbound = stmt->partbound;
cxt.ofType = (stmt->ofTypename != NULL);
/* /*
* Notice that we allow OIDs here only for plain tables, even though * Notice that we allow OIDs here only for plain tables, even though
...@@ -662,6 +665,15 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column) ...@@ -662,6 +665,15 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
Type ctype; Type ctype;
Oid typeOid; Oid typeOid;
if (cxt->ofType)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("identity colums are not supported on typed tables")));
if (cxt->partbound)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("identify columns are not supported on partitions")));
ctype = typenameType(cxt->pstate, column->typeName, NULL); ctype = typenameType(cxt->pstate, column->typeName, NULL);
typeOid = HeapTupleGetOid(ctype); typeOid = HeapTupleGetOid(ctype);
ReleaseSysCache(ctype); ReleaseSysCache(ctype);
...@@ -2697,6 +2709,7 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt, ...@@ -2697,6 +2709,7 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
cxt.pkey = NULL; cxt.pkey = NULL;
cxt.ispartitioned = (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE); cxt.ispartitioned = (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
cxt.partbound = NULL; cxt.partbound = NULL;
cxt.ofType = false;
/* /*
* The only subtypes that currently require parse transformation handling * The only subtypes that currently require parse transformation handling
......
...@@ -346,3 +346,15 @@ SELECT * FROM itest8; ...@@ -346,3 +346,15 @@ SELECT * FROM itest8;
RESET ROLE; RESET ROLE;
DROP TABLE itest8; DROP TABLE itest8;
DROP USER regress_user1; DROP USER regress_user1;
-- typed tables (currently not supported)
CREATE TYPE itest_type AS (f1 integer, f2 text, f3 bigint);
CREATE TABLE itest12 OF itest_type (f1 WITH OPTIONS GENERATED ALWAYS AS IDENTITY); -- error
ERROR: identity colums are not supported on typed tables
DROP TYPE itest_type CASCADE;
-- table partitions (currently not supported)
CREATE TABLE itest_parent (f1 date NOT NULL, f2 text, f3 bigint) PARTITION BY RANGE (f1);
CREATE TABLE itest_child PARTITION OF itest_parent (
f3 WITH OPTIONS GENERATED ALWAYS AS IDENTITY
) FOR VALUES FROM ('2016-07-01') TO ('2016-08-01'); -- error
ERROR: identify columns are not supported on partitions
DROP TABLE itest_parent;
...@@ -211,3 +211,19 @@ SELECT * FROM itest8; ...@@ -211,3 +211,19 @@ SELECT * FROM itest8;
RESET ROLE; RESET ROLE;
DROP TABLE itest8; DROP TABLE itest8;
DROP USER regress_user1; DROP USER regress_user1;
-- typed tables (currently not supported)
CREATE TYPE itest_type AS (f1 integer, f2 text, f3 bigint);
CREATE TABLE itest12 OF itest_type (f1 WITH OPTIONS GENERATED ALWAYS AS IDENTITY); -- error
DROP TYPE itest_type CASCADE;
-- table partitions (currently not supported)
CREATE TABLE itest_parent (f1 date NOT NULL, f2 text, f3 bigint) PARTITION BY RANGE (f1);
CREATE TABLE itest_child PARTITION OF itest_parent (
f3 WITH OPTIONS GENERATED ALWAYS AS IDENTITY
) FOR VALUES FROM ('2016-07-01') TO ('2016-08-01'); -- error
DROP TABLE itest_parent;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment