Skip to content

Commit

Permalink
Raise a error on an attempt to partition a Global Temporary Table. Th…
Browse files Browse the repository at this point in the history
…is is

not supported, again not because PostgreSQL do not allow partition on
temporary table but because other RDBMS like Oracle, DB2 and MySQL do not
support it.

Add a regression test on partitioning.
  • Loading branch information
darold committed May 2, 2020
1 parent f7810c8 commit 49bfeef
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ DATA = $(wildcard updates/*--*.sql) sql/$(EXTENSION)--$(EXTVERSION).sql
TESTS = 00_init 01_oncommitdelete 02_oncommitpreserve \
03_createontruncate 04_rename 05_useindex \
06_createas 07_createlike 08_plplgsql \
09_transaction 10_foreignkey
09_transaction 10_foreignkey 11_partition

REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))
REGRESS_OPTS = --inputdir=test
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,13 @@ SQL Server or MySQL.

ORA-14455: attempt to create referential integrity constraint on temporary table.

#### Partitioning

Partitioning on Global Temporary Table is not supported, again not because
PostgreSQL do not allow partition on temporary table but because other RDBMS
like Oracle, DB2 and MySQL do not support it. SQL Server supports partition
on global temporary table.


### [How the extension really works](#how-the-extension-really-works)

Expand Down
8 changes: 8 additions & 0 deletions pgtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,14 @@ gtt_check_command(GTT_PROCESSUTILITY_PROTO)
if (regexec(&create_global_regexv, queryString, 0, 0, 0) != 0)
break;

/*
* We do not allow partitioning on GTT, not that PostgreSQL can
* not do it but because we want to mimic the Oracle or other
* RDBMS behavior.
*/
if (stmt->partspec != NULL)
elog(ERROR, "Global Temporary Table do not support partitioning.");

/*
* What to do at commit time for global temporary relations
* default is ON COMMIT PRESERVE ROWS (do nothing)
Expand Down
8 changes: 8 additions & 0 deletions test/expected/10_foreignkey.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
----
-- Regression test to Global Temporary Table implementation
--
-- Test for unsupported foreign keys on GTT.
--
----
-- Import the library
LOAD 'pgtt';
-- Must throw ERROR: attempt to create referential integrity constraint on temporary table.
CREATE /*GLOBAL*/ TEMPORARY TABLE t2 (c1 integer, FOREIGN KEY (c1) REFERENCES source (id));
Expand All @@ -8,3 +15,4 @@ CREATE /*GLOBAL*/ TEMPORARY TABLE t2 (c1 integer);
-- Must throw ERROR: attempt to create referential integrity constraint on temporary table.
ALTER TABLE t2 ADD FOREIGN KEY (c1) REFERENCES source (id);
ERROR: attempt to create referential integrity constraint on global temporary table
ROLLBACK;
15 changes: 15 additions & 0 deletions test/expected/11_partition.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
----
-- Regression test to Global Temporary Table implementation
--
-- Test for unsupported partitioning on GTT.
--
----
-- Import the library
LOAD 'pgtt';
-- Must throw ERROR: Global Temporary Table do not support partitioning.
CREATE /*GLOBAL*/ TEMPORARY TABLE measurement (
logdate date not null,
peaktemp int,
unitsales int
) PARTITION BY RANGE (logdate);
ERROR: Global Temporary Table do not support partitioning.
9 changes: 8 additions & 1 deletion test/sql/10_foreignkey.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
----
-- Regression test to Global Temporary Table implementation
--
-- Test for unsupported foreign keys on GTT.
--
----
-- Import the library
LOAD 'pgtt';
-- Must throw ERROR: attempt to create referential integrity constraint on temporary table.
CREATE /*GLOBAL*/ TEMPORARY TABLE t2 (c1 integer, FOREIGN KEY (c1) REFERENCES source (id));
BEGIN;
CREATE /*GLOBAL*/ TEMPORARY TABLE t2 (c1 integer);
-- Must throw ERROR: attempt to create referential integrity constraint on temporary table.
ALTER TABLE t2 ADD FOREIGN KEY (c1) REFERENCES source (id);

ROLLBACK;
14 changes: 14 additions & 0 deletions test/sql/11_partition.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
----
-- Regression test to Global Temporary Table implementation
--
-- Test for unsupported partitioning on GTT.
--
----
-- Import the library
LOAD 'pgtt';
-- Must throw ERROR: Global Temporary Table do not support partitioning.
CREATE /*GLOBAL*/ TEMPORARY TABLE measurement (
logdate date not null,
peaktemp int,
unitsales int
) PARTITION BY RANGE (logdate);

0 comments on commit 49bfeef

Please sign in to comment.