Skip to content

Commit 6cfdd79

Browse files
jwdeitcherimatnor
authored andcommitted
Prevent native partitioning attachment of hypertables
- Raise an exception upon an attach partition event on a hypertable to a native postgres partition
1 parent 438d79d commit 6cfdd79

File tree

6 files changed

+89
-1
lines changed

6 files changed

+89
-1
lines changed

src/process_utility.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,24 @@ process_altertable_start_table(Node *parsetree)
12911291
if (ht != NULL)
12921292
process_alter_column_type_start(ht, cmd);
12931293
break;
1294+
#if PG10
1295+
case AT_AttachPartition:
1296+
{
1297+
RangeVar *relation;
1298+
PartitionCmd *partstmt;
1299+
1300+
partstmt = (PartitionCmd *) cmd->def;
1301+
relation = partstmt->name;
1302+
Assert(NULL != relation);
1303+
1304+
if (InvalidOid != hypertable_relid(relation))
1305+
{
1306+
ereport(ERROR,
1307+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1308+
errmsg("Hypertables do not support native postgres partitioning")));
1309+
}
1310+
}
1311+
#endif
12941312
default:
12951313
break;
12961314
}

test/expected/partitioning-10.out

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- Should expect an error when creating a hypertable from a partition
2+
\set ON_ERROR_STOP 0
3+
CREATE TABLE partitioned_ht_create(time timestamptz, temp float, device int) PARTITION BY RANGE (time);
4+
SELECT create_hypertable('partitioned_ht_create', 'time');
5+
ERROR: table public.partitioned_ht_create is already partitioned
6+
\set ON_ERROR_STOP 1
7+
-- Should expect an error when attaching a hypertable to a partition
8+
\set ON_ERROR_STOP 0
9+
CREATE TABLE partitioned_attachment_vanilla(time timestamptz, temp float, device int) PARTITION BY RANGE (time);
10+
CREATE TABLE attachment_hypertable(time timestamptz, temp float, device int);
11+
SELECT create_hypertable('attachment_hypertable', 'time');
12+
NOTICE: Adding NOT NULL constraint to time column time (NULL time values not allowed)
13+
create_hypertable
14+
-------------------
15+
16+
(1 row)
17+
18+
ALTER TABLE partitioned_attachment_vanilla ATTACH PARTITION attachment_hypertable FOR VALUES FROM ('2016-07-01') TO ('2016-08-01');
19+
ERROR: Hypertables do not support native postgres partitioning
20+
\set ON_ERROR_STOP 1
21+
-- Should not expect an error when attaching a normal table to a partition
22+
CREATE TABLE partitioned_vanilla(time timestamptz, temp float, device int) PARTITION BY RANGE (time);
23+
CREATE TABLE attachment_vanilla(time timestamptz, temp float, device int);
24+
ALTER TABLE partitioned_vanilla ATTACH PARTITION attachment_vanilla FOR VALUES FROM ('2016-07-01') TO ('2016-08-01');

test/expected/partitioning-9.6.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-- Should expect an error when creating a hypertable from a partition
2+
\set ON_ERROR_STOP 0
3+
CREATE TABLE partitioned_ht_create(time timestamptz, temp float, device int) PARTITION BY RANGE (time);
4+
ERROR: syntax error at or near "PARTITION" at character 78
5+
SELECT create_hypertable('partitioned_ht_create', 'time');
6+
ERROR: relation "partitioned_ht_create" does not exist at character 26
7+
\set ON_ERROR_STOP 1
8+
-- Should expect an error when attaching a hypertable to a partition
9+
\set ON_ERROR_STOP 0
10+
CREATE TABLE partitioned_attachment_vanilla(time timestamptz, temp float, device int) PARTITION BY RANGE (time);
11+
ERROR: syntax error at or near "PARTITION" at character 87
12+
CREATE TABLE attachment_hypertable(time timestamptz, temp float, device int);
13+
SELECT create_hypertable('attachment_hypertable', 'time');
14+
NOTICE: Adding NOT NULL constraint to time column time (NULL time values not allowed)
15+
create_hypertable
16+
-------------------
17+
18+
(1 row)
19+
20+
ALTER TABLE partitioned_attachment_vanilla ATTACH PARTITION attachment_hypertable FOR VALUES FROM ('2016-07-01') TO ('2016-08-01');
21+
ERROR: syntax error at or near "ATTACH" at character 44
22+
\set ON_ERROR_STOP 1
23+
-- Should not expect an error when attaching a normal table to a partition
24+
CREATE TABLE partitioned_vanilla(time timestamptz, temp float, device int) PARTITION BY RANGE (time);
25+
ERROR: syntax error at or near "PARTITION" at character 76

test/sql/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
/parallel-9.6.sql
22
/parallel-10.0.sql
3+
/partitioning-9.6.sql
4+
/partitioning-10.sql

test/sql/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ set(TEST_FILES
4949
version.sql)
5050

5151
set(TEST_TEMPLATES
52-
parallel.sql.in)
52+
parallel.sql.in
53+
partitioning.sql.in)
5354

5455
# Regression tests that vary with PostgreSQL version. Generated test
5556
# files are put in the original source directory since all tests must

test/sql/partitioning.sql.in

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- Should expect an error when creating a hypertable from a partition
2+
\set ON_ERROR_STOP 0
3+
CREATE TABLE partitioned_ht_create(time timestamptz, temp float, device int) PARTITION BY RANGE (time);
4+
SELECT create_hypertable('partitioned_ht_create', 'time');
5+
\set ON_ERROR_STOP 1
6+
7+
-- Should expect an error when attaching a hypertable to a partition
8+
\set ON_ERROR_STOP 0
9+
CREATE TABLE partitioned_attachment_vanilla(time timestamptz, temp float, device int) PARTITION BY RANGE (time);
10+
CREATE TABLE attachment_hypertable(time timestamptz, temp float, device int);
11+
SELECT create_hypertable('attachment_hypertable', 'time');
12+
ALTER TABLE partitioned_attachment_vanilla ATTACH PARTITION attachment_hypertable FOR VALUES FROM ('2016-07-01') TO ('2016-08-01');
13+
\set ON_ERROR_STOP 1
14+
15+
-- Should not expect an error when attaching a normal table to a partition
16+
CREATE TABLE partitioned_vanilla(time timestamptz, temp float, device int) PARTITION BY RANGE (time);
17+
CREATE TABLE attachment_vanilla(time timestamptz, temp float, device int);
18+
ALTER TABLE partitioned_vanilla ATTACH PARTITION attachment_vanilla FOR VALUES FROM ('2016-07-01') TO ('2016-08-01');

0 commit comments

Comments
 (0)