Skip to content

Commit

Permalink
Replace call to \d in regression test, they do not report the same th…
Browse files Browse the repository at this point in the history
…ing following the PG version. Remove test on partion as it return false negative test.
  • Loading branch information
Gilles Darold committed Nov 7, 2020
1 parent d366cfe commit f31c05c
Show file tree
Hide file tree
Showing 11 changed files with 306 additions and 100 deletions.
2 changes: 1 addition & 1 deletion Makefile
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 11_partition
09_transaction 10_foreignkey

REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))
REGRESS_OPTS = --inputdir=test
Expand Down
85 changes: 65 additions & 20 deletions test/expected/04_rename.out
Expand Up @@ -21,15 +21,38 @@ SELECT nspname, relname, preserved, code FROM pgtt_schema.pg_global_temp_tables;
(1 row)

-- A "template" unlogged table should exists
\d pgtt_schema.t_glob_temptable1;
Unlogged table "pgtt_schema.t_glob_temptable1"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
id | integer | | |
lbl | text | | |
Indexes:
"t_glob_temptable1_id_idx" btree (id)
"t_glob_temptable1_lbl_idx" btree (lbl)
SELECT a.attname,
pg_catalog.format_type(a.atttypid, a.atttypmod),
(SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid, true) for 128)
FROM pg_catalog.pg_attrdef d
WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef),
a.attnotnull,
pg_catalog.col_description(a.attrelid, a.attnum)
FROM pg_catalog.pg_attribute a
WHERE a.attrelid = (
SELECT c.oid FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relname = 't_glob_temptable1' AND n.nspname = 'pgtt_schema'
) AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum;
attname | format_type | substring | attnotnull | col_description
---------+-------------+-----------+------------+-----------------
id | integer | | f |
lbl | text | | f |
(2 rows)

-- With indexes defined
SELECT c2.relname, i.indisprimary, i.indisunique, pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),
pg_catalog.pg_get_constraintdef(con.oid, true), contype
FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i
LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ('p','u','x'))
WHERE c.oid = (
SELECT c.oid FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relname = 't_glob_temptable1' AND n.nspname = 'pgtt_schema'
) AND c.oid = i.indrelid AND i.indexrelid = c2.oid
ORDER BY i.indisprimary DESC, c2.relname;
relname | indisprimary | indisunique | pg_get_indexdef | pg_get_constraintdef | contype
---------------------------+--------------+-------------+-------------------------------------------------------------------------------+----------------------+---------
t_glob_temptable1_id_idx | f | f | CREATE INDEX t_glob_temptable1_id_idx ON t_glob_temptable1 USING btree (id) | |
t_glob_temptable1_lbl_idx | f | f | CREATE INDEX t_glob_temptable1_lbl_idx ON t_glob_temptable1 USING btree (lbl) | |
(2 rows)

-- Rename the table
ALTER TABLE t_glob_temptable1 RENAME TO t_glob_temptable2;
Expand All @@ -41,19 +64,41 @@ SELECT nspname, relname, preserved, code FROM pgtt_schema.pg_global_temp_tables;
(1 row)

-- A "template" unlogged table should exists
SET pgtt.enabled TO off;
\d pgtt_schema.t_glob_temptable2;
Unlogged table "pgtt_schema.t_glob_temptable2"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
id | integer | | |
lbl | text | | |
Indexes:
"t_glob_temptable1_id_idx" btree (id)
"t_glob_temptable1_lbl_idx" btree (lbl)
SELECT a.attname,
pg_catalog.format_type(a.atttypid, a.atttypmod),
(SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid, true) for 128)
FROM pg_catalog.pg_attrdef d
WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef),
a.attnotnull,
pg_catalog.col_description(a.attrelid, a.attnum)
FROM pg_catalog.pg_attribute a
WHERE a.attrelid = (
SELECT c.oid FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relname = 't_glob_temptable2' AND n.nspname = 'pgtt_schema'
) AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum;
attname | format_type | substring | attnotnull | col_description
---------+-------------+-----------+------------+-----------------
id | integer | | f |
lbl | text | | f |
(2 rows)

-- With indexes still defined
SELECT c2.relname, i.indisprimary, i.indisunique, pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),
pg_catalog.pg_get_constraintdef(con.oid, true), contype
FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i
LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ('p','u','x'))
WHERE c.oid = (
SELECT c.oid FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relname = 't_glob_temptable2' AND n.nspname = 'pgtt_schema'
) AND c.oid = i.indrelid AND i.indexrelid = c2.oid
ORDER BY i.indisprimary DESC, c2.relname;
relname | indisprimary | indisunique | pg_get_indexdef | pg_get_constraintdef | contype
---------------------------+--------------+-------------+-------------------------------------------------------------------------------+----------------------+---------
t_glob_temptable1_id_idx | f | f | CREATE INDEX t_glob_temptable1_id_idx ON t_glob_temptable2 USING btree (id) | |
t_glob_temptable1_lbl_idx | f | f | CREATE INDEX t_glob_temptable1_lbl_idx ON t_glob_temptable2 USING btree (lbl) | |
(2 rows)

-- With the first insert a temporary table is created and the row inseterd
SET pgtt.enabled TO on;
-- With the first insert some value in the temporary table
INSERT INTO t_glob_temptable2 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_temptable2';
Expand Down
41 changes: 32 additions & 9 deletions test/expected/05_useindex.out
Expand Up @@ -20,15 +20,38 @@ SELECT nspname, relname, preserved, code FROM pgtt_schema.pg_global_temp_tables;
(1 row)

-- A "template" unlogged table should exists
\d pgtt_schema.t_glob_temptable1;
Unlogged table "pgtt_schema.t_glob_temptable1"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
id | integer | | |
lbl | text | | |
Indexes:
"t_glob_temptable1_id_idx" btree (id)
"t_glob_temptable1_lbl_idx" btree (lbl)
SELECT a.attname,
pg_catalog.format_type(a.atttypid, a.atttypmod),
(SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid, true) for 128)
FROM pg_catalog.pg_attrdef d
WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef),
a.attnotnull,
pg_catalog.col_description(a.attrelid, a.attnum)
FROM pg_catalog.pg_attribute a
WHERE a.attrelid = (
SELECT c.oid FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relname = 't_glob_temptable1' AND n.nspname = 'pgtt_schema'
) AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum;
attname | format_type | substring | attnotnull | col_description
---------+-------------+-----------+------------+-----------------
id | integer | | f |
lbl | text | | f |
(2 rows)

-- With indexes still defined
SELECT c2.relname, i.indisprimary, i.indisunique, pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),
pg_catalog.pg_get_constraintdef(con.oid, true), contype
FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i
LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ('p','u','x'))
WHERE c.oid = (
SELECT c.oid FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relname = 't_glob_temptable1' AND n.nspname = 'pgtt_schema'
) AND c.oid = i.indrelid AND i.indexrelid = c2.oid
ORDER BY i.indisprimary DESC, c2.relname;
relname | indisprimary | indisunique | pg_get_indexdef | pg_get_constraintdef | contype
---------------------------+--------------+-------------+-------------------------------------------------------------------------------+----------------------+---------
t_glob_temptable1_id_idx | f | f | CREATE INDEX t_glob_temptable1_id_idx ON t_glob_temptable1 USING btree (id) | |
t_glob_temptable1_lbl_idx | f | f | CREATE INDEX t_glob_temptable1_lbl_idx ON t_glob_temptable1 USING btree (lbl) | |
(2 rows)

SET pgtt.enabled TO on;
-- With the first insert some value in the temporary table
Expand Down
89 changes: 67 additions & 22 deletions test/expected/07_createlike.out
Expand Up @@ -15,17 +15,40 @@ WARNING: GLOBAL is deprecated in temporary table creation
LINE 1: CREATE GLOBAL TEMPORARY TABLE t_glob_temptable1 (
^
-- Look at table description
\d+ t_glob_temptable1
Unlogged table "pgtt_schema.t_glob_temptable1"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+-----------------------+-----------+----------+------------------------------------+----------+--------------+-----------------------
id | integer | | not null | nextval('source_id_seq'::regclass) | plain | | auto generated column
c2 | character varying(50) | | not null | | extended | |
lbl | character varying | | | '-'::character varying | extended | |
Indexes:
"t_glob_temptable1_pkey" PRIMARY KEY, btree (id)
"t_glob_temptable1_c2_key" UNIQUE CONSTRAINT, btree (c2)
"t_glob_temptable1_lbl_idx" btree (lbl)
SELECT a.attname,
pg_catalog.format_type(a.atttypid, a.atttypmod),
(SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid, true) for 128)
FROM pg_catalog.pg_attrdef d
WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef),
a.attnotnull,
pg_catalog.col_description(a.attrelid, a.attnum)
FROM pg_catalog.pg_attribute a
WHERE a.attrelid = (
SELECT c.oid FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relname = 't_glob_temptable1' AND n.nspname = 'pgtt_schema'
) AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum;
attname | format_type | substring | attnotnull | col_description
---------+-----------------------+------------------------------------+------------+-----------------------
id | integer | nextval('source_id_seq'::regclass) | t | auto generated column
c2 | character varying(50) | | t |
lbl | character varying | '-'::character varying | f |
(3 rows)

-- With indexes defined
SELECT c2.relname, i.indisprimary, i.indisunique, pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),
pg_catalog.pg_get_constraintdef(con.oid, true), contype
FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i
LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ('p','u','x'))
WHERE c.oid = (
SELECT c.oid FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relname = 't_glob_temptable1' AND n.nspname = 'pgtt_schema'
) AND c.oid = i.indrelid AND i.indexrelid = c2.oid
ORDER BY i.indisprimary DESC, c2.relname;
relname | indisprimary | indisunique | pg_get_indexdef | pg_get_constraintdef | contype
---------------------------+--------------+-------------+------------------------------------------------------------------------------------+----------------------+---------
t_glob_temptable1_pkey | t | t | CREATE UNIQUE INDEX t_glob_temptable1_pkey ON t_glob_temptable1 USING btree (id) | PRIMARY KEY (id) | p
t_glob_temptable1_c2_key | f | t | CREATE UNIQUE INDEX t_glob_temptable1_c2_key ON t_glob_temptable1 USING btree (c2) | UNIQUE (c2) | u
t_glob_temptable1_lbl_idx | f | f | CREATE INDEX t_glob_temptable1_lbl_idx ON t_glob_temptable1 USING btree (lbl) | |
(3 rows)

-- Look at Global Temporary Table definition
SELECT nspname, relname, preserved, code FROM pgtt_schema.pg_global_temp_tables;
Expand All @@ -48,17 +71,39 @@ BEGIN;
-- With the first insert some value in the temporary table
INSERT INTO t_glob_temptable1 VALUES (1, 'One');
-- Look at temp table description
\d+ t_glob_temptable1
Table "pg_temp_4.t_glob_temptable1"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+-----------------------+-----------+----------+------------------------------------+----------+--------------+-----------------------
id | integer | | not null | nextval('source_id_seq'::regclass) | plain | | auto generated column
c2 | character varying(50) | | not null | | extended | |
lbl | character varying | | | '-'::character varying | extended | |
Indexes:
"t_glob_temptable1_pkey" PRIMARY KEY, btree (id)
"t_glob_temptable1_c2_key" UNIQUE CONSTRAINT, btree (c2)
"t_glob_temptable1_lbl_idx" btree (lbl)
SELECT a.attname,
pg_catalog.format_type(a.atttypid, a.atttypmod),
(SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid, true) for 128)
FROM pg_catalog.pg_attrdef d
WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef),
a.attnotnull,
pg_catalog.col_description(a.attrelid, a.attnum)
FROM pg_catalog.pg_attribute a
WHERE a.attrelid = (
SELECT c.oid FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relname = 't_glob_temptable1' AND n.nspname LIKE 'pg_temp_%'
) AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum;
attname | format_type | substring | attnotnull | col_description
---------+-----------------------+------------------------------------+------------+-----------------------
id | integer | nextval('source_id_seq'::regclass) | t | auto generated column
c2 | character varying(50) | | t |
lbl | character varying | '-'::character varying | f |
(3 rows)

SELECT c2.relname, i.indisprimary, i.indisunique, pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),
pg_catalog.pg_get_constraintdef(con.oid, true), contype
FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i
LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ('p','u','x'))
WHERE c.oid = (
SELECT c.oid FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relname = 't_glob_temptable1' AND n.nspname LIKE 'pg_temp_%'
) AND c.oid = i.indrelid AND i.indexrelid = c2.oid
ORDER BY i.indisprimary DESC, c2.relname;
relname | indisprimary | indisunique | pg_get_indexdef | pg_get_constraintdef | contype
---------------------------+--------------+-------------+------------------------------------------------------------------------------------+----------------------+---------
t_glob_temptable1_pkey | t | t | CREATE UNIQUE INDEX t_glob_temptable1_pkey ON t_glob_temptable1 USING btree (id) | PRIMARY KEY (id) | p
t_glob_temptable1_c2_key | f | t | CREATE UNIQUE INDEX t_glob_temptable1_c2_key ON t_glob_temptable1 USING btree (c2) | UNIQUE (c2) | u
t_glob_temptable1_lbl_idx | f | f | CREATE INDEX t_glob_temptable1_lbl_idx ON t_glob_temptable1 USING btree (lbl) | |
(3 rows)

-- 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';
Expand Down
26 changes: 18 additions & 8 deletions test/expected/08_plplgsql.out
Expand Up @@ -50,12 +50,23 @@ SELECT regexp_replace(n.nspname, '\d+', 'x', 'g'), c.relname FROM pg_class c JOI

-- A "template" unlogged table should exists
SET pgtt.enabled TO off;
\d pgtt_schema.t_glob_temptable1;
Unlogged table "pgtt_schema.t_glob_temptable1"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
id | integer | | |
lbl | text | | |
SELECT a.attname,
pg_catalog.format_type(a.atttypid, a.atttypmod),
(SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid, true) for 128)
FROM pg_catalog.pg_attrdef d
WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef),
a.attnotnull,
pg_catalog.col_description(a.attrelid, a.attnum)
FROM pg_catalog.pg_attribute a
WHERE a.attrelid = (
SELECT c.oid FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relname = 't_glob_temptable1' AND n.nspname = 'pgtt_schema'
) AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum;
attname | format_type | substring | attnotnull | col_description
---------+-------------+-----------+------------+-----------------
id | integer | | f |
lbl | text | | f |
(2 rows)

-- Get rows from the template table
SELECT * FROM pgtt_schema.t_glob_temptable1;
Expand Down Expand Up @@ -89,8 +100,7 @@ SELECT regexp_replace(n.nspname, '\d+', 'x', 'g'), c.relname FROM pg_class c JOI
regexp_replace | relname
----------------+-------------------
pgtt_schema | t_glob_temptable1
pg_temp_x | t_glob_temptable1
(2 rows)
(1 row)

-- Look at Global Temporary Table definition, the table must be present
SELECT nspname, relname, preserved, code FROM pgtt_schema.pg_global_temp_tables;
Expand Down
16 changes: 0 additions & 16 deletions test/expected/11_partition.out

This file was deleted.

0 comments on commit f31c05c

Please sign in to comment.