Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix error with temporary table not created but still in cache after a…
… rollback.
- Loading branch information
Showing
8 changed files
with
180 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
-- Import the library | ||
LOAD 'pgtt'; | ||
-- Create a GTT like table to test ON COMMIT DELETE ROWS | ||
CREATE GLOBAL TEMPORARY TABLE t_glob_temptable1 (id integer, lbl text) ON COMMIT DELETE ROWS; | ||
WARNING: GLOBAL is deprecated in temporary table creation | ||
LINE 1: CREATE GLOBAL TEMPORARY TABLE t_glob_temptable1 (id integer,... | ||
^ | ||
-- Look at Global Temporary Table definition | ||
SELECT nspname, relname, preserved, code FROM pgtt_schema.pg_global_temp_tables; | ||
nspname | relname | preserved | code | ||
-------------+-------------------+-----------+---------------------- | ||
pgtt_schema | t_glob_temptable1 | f | id integer, lbl text | ||
(1 row) | ||
|
||
-- A "template" unlogged table should exists | ||
SELECT n.nspname, c.relname FROM pg_class c JOIN pg_namespace n ON (c.relnamespace=n.oid) WHERE relname = 't_glob_temptable1'; | ||
nspname | relname | ||
-------------+------------------- | ||
pgtt_schema | t_glob_temptable1 | ||
(1 row) | ||
|
||
BEGIN; | ||
-- With the first insert some value in the temporary table | ||
INSERT INTO t_glob_temptable1 VALUES (1, 'One'); | ||
-- Look if we have two tables now | ||
SELECT regexp_replace(n.nspname, '\d+', 'x', 'g'), c.relname FROM pg_class c JOIN pg_namespace n ON (c.relnamespace=n.oid) WHERE relname = 't_glob_temptable1'; | ||
regexp_replace | relname | ||
----------------+------------------- | ||
pgtt_schema | t_glob_temptable1 | ||
pg_temp_x | t_glob_temptable1 | ||
(2 rows) | ||
|
||
-- Verify the registering of the temporary table | ||
SELECT nspname, relname, preserved, code FROM pgtt_schema.pg_global_temp_tables; | ||
nspname | relname | preserved | code | ||
-------------+-------------------+-----------+---------------------- | ||
pgtt_schema | t_glob_temptable1 | f | id integer, lbl text | ||
(1 row) | ||
|
||
-- Second insert failure | ||
INSERT INTO t_glob_temptable1 VALUES ('Two', 2); | ||
ERROR: invalid input syntax for type integer: "Two" | ||
LINE 1: INSERT INTO t_glob_temptable1 VALUES ('Two', 2); | ||
^ | ||
ROLLBACK; | ||
-- Look if we have two tables now | ||
SELECT regexp_replace(n.nspname, '\d+', 'x', 'g'), c.relname FROM pg_class c JOIN pg_namespace n ON (c.relnamespace=n.oid) WHERE relname = 't_glob_temptable1'; | ||
regexp_replace | relname | ||
----------------+------------------- | ||
pgtt_schema | t_glob_temptable1 | ||
(1 row) | ||
|
||
-- Insert a new row | ||
BEGIN; | ||
-- With the first insert some value in the temporary table | ||
-- Should not return an error that table doesn't exists | ||
INSERT INTO t_glob_temptable1 VALUES (2, 'Two'); | ||
-- Look if we have two tables now | ||
SELECT regexp_replace(n.nspname, '\d+', 'x', 'g'), c.relname FROM pg_class c JOIN pg_namespace n ON (c.relnamespace=n.oid) WHERE relname = 't_glob_temptable1'; | ||
regexp_replace | relname | ||
----------------+------------------- | ||
pgtt_schema | t_glob_temptable1 | ||
pg_temp_x | t_glob_temptable1 | ||
(2 rows) | ||
|
||
-- Verify the insert | ||
SELECT * FROM t_glob_temptable1; | ||
id | lbl | ||
----+----- | ||
2 | Two | ||
(1 row) | ||
|
||
COMMIT; | ||
-- Reconnect and drop the GTT | ||
\c - - | ||
LOAD 'pgtt'; | ||
SHOW search_path; | ||
search_path | ||
-------------------- | ||
public,pgtt_schema | ||
(1 row) | ||
|
||
DROP TABLE t_glob_temptable1; | ||
-- Look at Global Temporary Table definition | ||
SELECT nspname, relname, preserved, code FROM pgtt_schema.pg_global_temp_tables; -- should be empty | ||
nspname | relname | preserved | code | ||
---------+---------+-----------+------ | ||
(0 rows) | ||
|
||
-- The "template" unlogged table should not exists anymore | ||
SELECT n.nspname, c.relname FROM pg_class c JOIN pg_namespace n ON (c.relnamespace=n.oid) WHERE relname = 't_glob_temptable1'; | ||
nspname | relname | ||
---------+--------- | ||
(0 rows) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
-- Import the library | ||
LOAD 'pgtt'; | ||
|
||
-- Create a GTT like table to test ON COMMIT DELETE ROWS | ||
CREATE GLOBAL TEMPORARY TABLE t_glob_temptable1 (id integer, lbl text) ON COMMIT DELETE ROWS; | ||
|
||
-- Look at Global Temporary Table definition | ||
SELECT nspname, relname, preserved, code FROM pgtt_schema.pg_global_temp_tables; | ||
|
||
-- A "template" unlogged table should exists | ||
SELECT n.nspname, c.relname FROM pg_class c JOIN pg_namespace n ON (c.relnamespace=n.oid) WHERE relname = 't_glob_temptable1'; | ||
|
||
BEGIN; | ||
|
||
-- With the first insert some value in the temporary table | ||
INSERT INTO t_glob_temptable1 VALUES (1, 'One'); | ||
|
||
-- Look if we have two tables now | ||
SELECT regexp_replace(n.nspname, '\d+', 'x', 'g'), c.relname FROM pg_class c JOIN pg_namespace n ON (c.relnamespace=n.oid) WHERE relname = 't_glob_temptable1'; | ||
|
||
-- Verify the registering of the temporary table | ||
SELECT nspname, relname, preserved, code FROM pgtt_schema.pg_global_temp_tables; | ||
|
||
-- Second insert failure | ||
INSERT INTO t_glob_temptable1 VALUES ('Two', 2); | ||
|
||
ROLLBACK; | ||
|
||
-- Look if we have two tables now | ||
SELECT regexp_replace(n.nspname, '\d+', 'x', 'g'), c.relname FROM pg_class c JOIN pg_namespace n ON (c.relnamespace=n.oid) WHERE relname = 't_glob_temptable1'; | ||
|
||
-- Insert a new row | ||
BEGIN; | ||
|
||
-- With the first insert some value in the temporary table | ||
-- Should not return an error that table doesn't exists | ||
INSERT INTO t_glob_temptable1 VALUES (2, 'Two'); | ||
|
||
-- Look if we have two tables now | ||
SELECT regexp_replace(n.nspname, '\d+', 'x', 'g'), c.relname FROM pg_class c JOIN pg_namespace n ON (c.relnamespace=n.oid) WHERE relname = 't_glob_temptable1'; | ||
|
||
-- Verify the insert | ||
SELECT * FROM t_glob_temptable1; | ||
|
||
COMMIT; | ||
|
||
-- Reconnect and drop the GTT | ||
\c - - | ||
|
||
LOAD 'pgtt'; | ||
|
||
SHOW search_path; | ||
DROP TABLE t_glob_temptable1; | ||
|
||
-- Look at Global Temporary Table definition | ||
SELECT nspname, relname, preserved, code FROM pgtt_schema.pg_global_temp_tables; -- should be empty | ||
|
||
-- The "template" unlogged table should not exists anymore | ||
SELECT n.nspname, c.relname FROM pg_class c JOIN pg_namespace n ON (c.relnamespace=n.oid) WHERE relname = 't_glob_temptable1'; | ||
|