Commit 2cf8c7aa authored by Tom Lane's avatar Tom Lane

Clean up duplicate table and function names in regression tests.

Many of the objects we create during the regression tests are put in the
public schema, so that using the same names in different regression tests
creates a hazard of test failures if any two such scripts run concurrently.
This patch cleans up a bunch of latent hazards of that sort, as well as two
live hazards.

The current situation in this regard is far worse than it was a year or two
back, because practically all of the partitioning-related test cases have
reused table names with enthusiasm.  I despaired of cleaning up that mess
within the five most-affected tests (create_table, alter_table, insert,
update, inherit); fortunately those don't run concurrently.

Other than partitioning problems, most of the issues boil down to using
names like "foo", "bar", "tmp", etc, without thought for the fact that
other test scripts might use similar names concurrently.  I've made an
effort to make all such names more specific.

One of the live hazards was that commit 7421f4b8 caused with.sql to
create a table named "test", conflicting with a similarly-named table
in alter_table.sql; this was exposed in the buildfarm recently.
The other one was that join.sql and transactions.sql both create tables
named "foo" and "bar"; but join.sql's uses of those names date back
only to December or so.

Since commit 7421f4b8 was back-patched to v10, back-patch a minimal
fix for that problem.  The rest of this is just future-proofing.

Discussion: https://postgr.es/m/4627.1521070268@sss.pgh.pa.us
parent 1466bcfa
This diff is collapsed.
...@@ -8,7 +8,7 @@ ERROR: random() is not a procedure ...@@ -8,7 +8,7 @@ ERROR: random() is not a procedure
LINE 1: CALL random(); LINE 1: CALL random();
^ ^
HINT: To call a function, use SELECT. HINT: To call a function, use SELECT.
CREATE FUNCTION testfunc1(a int) RETURNS int LANGUAGE SQL AS $$ SELECT a $$; CREATE FUNCTION cp_testfunc1(a int) RETURNS int LANGUAGE SQL AS $$ SELECT a $$;
CREATE TABLE cp_test (a int, b text); CREATE TABLE cp_test (a int, b text);
CREATE PROCEDURE ptest1(x text) CREATE PROCEDURE ptest1(x text)
LANGUAGE SQL LANGUAGE SQL
...@@ -118,14 +118,14 @@ LINE 1: ALTER PROCEDURE ptest1(text) STRICT; ...@@ -118,14 +118,14 @@ LINE 1: ALTER PROCEDURE ptest1(text) STRICT;
^ ^
ALTER FUNCTION ptest1(text) VOLATILE; -- error: not a function ALTER FUNCTION ptest1(text) VOLATILE; -- error: not a function
ERROR: ptest1(text) is not a function ERROR: ptest1(text) is not a function
ALTER PROCEDURE testfunc1(int) VOLATILE; -- error: not a procedure ALTER PROCEDURE cp_testfunc1(int) VOLATILE; -- error: not a procedure
ERROR: testfunc1(integer) is not a procedure ERROR: cp_testfunc1(integer) is not a procedure
ALTER PROCEDURE nonexistent() VOLATILE; ALTER PROCEDURE nonexistent() VOLATILE;
ERROR: procedure nonexistent() does not exist ERROR: procedure nonexistent() does not exist
DROP FUNCTION ptest1(text); -- error: not a function DROP FUNCTION ptest1(text); -- error: not a function
ERROR: ptest1(text) is not a function ERROR: ptest1(text) is not a function
DROP PROCEDURE testfunc1(int); -- error: not a procedure DROP PROCEDURE cp_testfunc1(int); -- error: not a procedure
ERROR: testfunc1(integer) is not a procedure ERROR: cp_testfunc1(integer) is not a procedure
DROP PROCEDURE nonexistent(); DROP PROCEDURE nonexistent();
ERROR: procedure nonexistent() does not exist ERROR: procedure nonexistent() does not exist
-- privileges -- privileges
...@@ -141,11 +141,11 @@ SET ROLE regress_cp_user1; ...@@ -141,11 +141,11 @@ SET ROLE regress_cp_user1;
CALL ptest1('a'); -- ok CALL ptest1('a'); -- ok
RESET ROLE; RESET ROLE;
-- ROUTINE syntax -- ROUTINE syntax
ALTER ROUTINE testfunc1(int) RENAME TO testfunc1a; ALTER ROUTINE cp_testfunc1(int) RENAME TO cp_testfunc1a;
ALTER ROUTINE testfunc1a RENAME TO testfunc1; ALTER ROUTINE cp_testfunc1a RENAME TO cp_testfunc1;
ALTER ROUTINE ptest1(text) RENAME TO ptest1a; ALTER ROUTINE ptest1(text) RENAME TO ptest1a;
ALTER ROUTINE ptest1a RENAME TO ptest1; ALTER ROUTINE ptest1a RENAME TO ptest1;
DROP ROUTINE testfunc1(int); DROP ROUTINE cp_testfunc1(int);
-- cleanup -- cleanup
DROP PROCEDURE ptest1; DROP PROCEDURE ptest1;
DROP PROCEDURE ptest2; DROP PROCEDURE ptest2;
......
This diff is collapsed.
This diff is collapsed.
...@@ -254,27 +254,27 @@ NOTICE: 3 ...@@ -254,27 +254,27 @@ NOTICE: 3
-- Check that addition or removal of any partition is correctly dealt with by -- Check that addition or removal of any partition is correctly dealt with by
-- default partition table when it is being used in prepared statement. -- default partition table when it is being used in prepared statement.
create table list_parted (a int) partition by list(a); create table pc_list_parted (a int) partition by list(a);
create table list_part_null partition of list_parted for values in (null); create table pc_list_part_null partition of pc_list_parted for values in (null);
create table list_part_1 partition of list_parted for values in (1); create table pc_list_part_1 partition of pc_list_parted for values in (1);
create table list_part_def partition of list_parted default; create table pc_list_part_def partition of pc_list_parted default;
prepare pstmt_def_insert (int) as insert into list_part_def values($1); prepare pstmt_def_insert (int) as insert into pc_list_part_def values($1);
-- should fail -- should fail
execute pstmt_def_insert(null); execute pstmt_def_insert(null);
ERROR: new row for relation "list_part_def" violates partition constraint ERROR: new row for relation "pc_list_part_def" violates partition constraint
DETAIL: Failing row contains (null). DETAIL: Failing row contains (null).
execute pstmt_def_insert(1); execute pstmt_def_insert(1);
ERROR: new row for relation "list_part_def" violates partition constraint ERROR: new row for relation "pc_list_part_def" violates partition constraint
DETAIL: Failing row contains (1). DETAIL: Failing row contains (1).
create table list_part_2 partition of list_parted for values in (2); create table pc_list_part_2 partition of pc_list_parted for values in (2);
execute pstmt_def_insert(2); execute pstmt_def_insert(2);
ERROR: new row for relation "list_part_def" violates partition constraint ERROR: new row for relation "pc_list_part_def" violates partition constraint
DETAIL: Failing row contains (2). DETAIL: Failing row contains (2).
alter table list_parted detach partition list_part_null; alter table pc_list_parted detach partition pc_list_part_null;
-- should be ok -- should be ok
execute pstmt_def_insert(null); execute pstmt_def_insert(null);
drop table list_part_1; drop table pc_list_part_1;
-- should be ok -- should be ok
execute pstmt_def_insert(1); execute pstmt_def_insert(1);
drop table list_parted, list_part_null; drop table pc_list_parted, pc_list_part_null;
deallocate pstmt_def_insert; deallocate pstmt_def_insert;
This diff is collapsed.
...@@ -1303,31 +1303,31 @@ ERROR: cannot change name of input parameter "c" ...@@ -1303,31 +1303,31 @@ ERROR: cannot change name of input parameter "c"
HINT: Use DROP FUNCTION dfunc(character varying,numeric) first. HINT: Use DROP FUNCTION dfunc(character varying,numeric) first.
drop function dfunc(varchar, numeric); drop function dfunc(varchar, numeric);
--fail, named parameters are not unique --fail, named parameters are not unique
create function testfoo(a int, a int) returns int as $$ select 1;$$ language sql; create function testpolym(a int, a int) returns int as $$ select 1;$$ language sql;
ERROR: parameter name "a" used more than once ERROR: parameter name "a" used more than once
create function testfoo(int, out a int, out a int) returns int as $$ select 1;$$ language sql; create function testpolym(int, out a int, out a int) returns int as $$ select 1;$$ language sql;
ERROR: parameter name "a" used more than once ERROR: parameter name "a" used more than once
create function testfoo(out a int, inout a int) returns int as $$ select 1;$$ language sql; create function testpolym(out a int, inout a int) returns int as $$ select 1;$$ language sql;
ERROR: parameter name "a" used more than once ERROR: parameter name "a" used more than once
create function testfoo(a int, inout a int) returns int as $$ select 1;$$ language sql; create function testpolym(a int, inout a int) returns int as $$ select 1;$$ language sql;
ERROR: parameter name "a" used more than once ERROR: parameter name "a" used more than once
-- valid -- valid
create function testfoo(a int, out a int) returns int as $$ select $1;$$ language sql; create function testpolym(a int, out a int) returns int as $$ select $1;$$ language sql;
select testfoo(37); select testpolym(37);
testfoo testpolym
--------- -----------
37 37
(1 row) (1 row)
drop function testfoo(int); drop function testpolym(int);
create function testfoo(a int) returns table(a int) as $$ select $1;$$ language sql; create function testpolym(a int) returns table(a int) as $$ select $1;$$ language sql;
select * from testfoo(37); select * from testpolym(37);
a a
---- ----
37 37
(1 row) (1 row)
drop function testfoo(int); drop function testpolym(int);
-- test polymorphic params and defaults -- test polymorphic params and defaults
create function dfunc(a anyelement, b anyelement = null, flag bool = true) create function dfunc(a anyelement, b anyelement = null, flag bool = true)
returns anyelement as $$ returns anyelement as $$
......
This diff is collapsed.
This diff is collapsed.
...@@ -1175,47 +1175,47 @@ SELECT count(*) FROM shoe; ...@@ -1175,47 +1175,47 @@ SELECT count(*) FROM shoe;
-- --
-- Simple test of qualified ON INSERT ... this did not work in 7.0 ... -- Simple test of qualified ON INSERT ... this did not work in 7.0 ...
-- --
create table foo (f1 int); create table rules_foo (f1 int);
create table foo2 (f1 int); create table rules_foo2 (f1 int);
create rule foorule as on insert to foo where f1 < 100 create rule rules_foorule as on insert to rules_foo where f1 < 100
do instead nothing; do instead nothing;
insert into foo values(1); insert into rules_foo values(1);
insert into foo values(1001); insert into rules_foo values(1001);
select * from foo; select * from rules_foo;
f1 f1
------ ------
1001 1001
(1 row) (1 row)
drop rule foorule on foo; drop rule rules_foorule on rules_foo;
-- this should fail because f1 is not exposed for unqualified reference: -- this should fail because f1 is not exposed for unqualified reference:
create rule foorule as on insert to foo where f1 < 100 create rule rules_foorule as on insert to rules_foo where f1 < 100
do instead insert into foo2 values (f1); do instead insert into rules_foo2 values (f1);
ERROR: column "f1" does not exist ERROR: column "f1" does not exist
LINE 2: do instead insert into foo2 values (f1); LINE 2: do instead insert into rules_foo2 values (f1);
^ ^
HINT: There is a column named "f1" in table "old", but it cannot be referenced from this part of the query. HINT: There is a column named "f1" in table "old", but it cannot be referenced from this part of the query.
-- this is the correct way: -- this is the correct way:
create rule foorule as on insert to foo where f1 < 100 create rule rules_foorule as on insert to rules_foo where f1 < 100
do instead insert into foo2 values (new.f1); do instead insert into rules_foo2 values (new.f1);
insert into foo values(2); insert into rules_foo values(2);
insert into foo values(100); insert into rules_foo values(100);
select * from foo; select * from rules_foo;
f1 f1
------ ------
1001 1001
100 100
(2 rows) (2 rows)
select * from foo2; select * from rules_foo2;
f1 f1
---- ----
2 2
(1 row) (1 row)
drop rule foorule on foo; drop rule rules_foorule on rules_foo;
drop table foo; drop table rules_foo;
drop table foo2; drop table rules_foo2;
-- --
-- Test rules containing INSERT ... SELECT, which is a very ugly special -- Test rules containing INSERT ... SELECT, which is a very ugly special
-- case as of 7.1. Example is based on bug report from Joel Burton. -- case as of 7.1. Example is based on bug report from Joel Burton.
...@@ -2535,50 +2535,50 @@ DETAIL: Key (id3a, id3b)=(1, 13) is not present in table "rule_and_refint_t1". ...@@ -2535,50 +2535,50 @@ DETAIL: Key (id3a, id3b)=(1, 13) is not present in table "rule_and_refint_t1".
-- --
-- disallow dropping a view's rule (bug #5072) -- disallow dropping a view's rule (bug #5072)
-- --
create view fooview as select 'foo'::text; create view rules_fooview as select 'rules_foo'::text;
drop rule "_RETURN" on fooview; drop rule "_RETURN" on rules_fooview;
ERROR: cannot drop rule _RETURN on view fooview because view fooview requires it ERROR: cannot drop rule _RETURN on view rules_fooview because view rules_fooview requires it
HINT: You can drop view fooview instead. HINT: You can drop view rules_fooview instead.
drop view fooview; drop view rules_fooview;
-- --
-- test conversion of table to view (needed to load some pg_dump files) -- test conversion of table to view (needed to load some pg_dump files)
-- --
create table fooview (x int, y text); create table rules_fooview (x int, y text);
select xmin, * from fooview; select xmin, * from rules_fooview;
xmin | x | y xmin | x | y
------+---+--- ------+---+---
(0 rows) (0 rows)
create rule "_RETURN" as on select to fooview do instead create rule "_RETURN" as on select to rules_fooview do instead
select 1 as x, 'aaa'::text as y; select 1 as x, 'aaa'::text as y;
select * from fooview; select * from rules_fooview;
x | y x | y
---+----- ---+-----
1 | aaa 1 | aaa
(1 row) (1 row)
select xmin, * from fooview; -- fail, views don't have such a column select xmin, * from rules_fooview; -- fail, views don't have such a column
ERROR: column "xmin" does not exist ERROR: column "xmin" does not exist
LINE 1: select xmin, * from fooview; LINE 1: select xmin, * from rules_fooview;
^ ^
select reltoastrelid, relkind, relfrozenxid select reltoastrelid, relkind, relfrozenxid
from pg_class where oid = 'fooview'::regclass; from pg_class where oid = 'rules_fooview'::regclass;
reltoastrelid | relkind | relfrozenxid reltoastrelid | relkind | relfrozenxid
---------------+---------+-------------- ---------------+---------+--------------
0 | v | 0 0 | v | 0
(1 row) (1 row)
drop view fooview; drop view rules_fooview;
-- trying to convert a partitioned table to view is not allowed -- trying to convert a partitioned table to view is not allowed
create table fooview (x int, y text) partition by list (x); create table rules_fooview (x int, y text) partition by list (x);
create rule "_RETURN" as on select to fooview do instead create rule "_RETURN" as on select to rules_fooview do instead
select 1 as x, 'aaa'::text as y; select 1 as x, 'aaa'::text as y;
ERROR: cannot convert partitioned table "fooview" to a view ERROR: cannot convert partitioned table "rules_fooview" to a view
-- nor can one convert a partition to view -- nor can one convert a partition to view
create table fooview_part partition of fooview for values in (1); create table rules_fooview_part partition of rules_fooview for values in (1);
create rule "_RETURN" as on select to fooview_part do instead create rule "_RETURN" as on select to rules_fooview_part do instead
select 1 as x, 'aaa'::text as y; select 1 as x, 'aaa'::text as y;
ERROR: cannot convert partition "fooview_part" to a view ERROR: cannot convert partition "rules_fooview_part" to a view
-- --
-- check for planner problems with complex inherited UPDATES -- check for planner problems with complex inherited UPDATES
-- --
...@@ -3229,12 +3229,12 @@ SELECT pg_get_partkeydef(0); ...@@ -3229,12 +3229,12 @@ SELECT pg_get_partkeydef(0);
(1 row) (1 row)
-- test rename for a rule defined on a partitioned table -- test rename for a rule defined on a partitioned table
CREATE TABLE parted_table (a int) PARTITION BY LIST (a); CREATE TABLE rules_parted_table (a int) PARTITION BY LIST (a);
CREATE TABLE parted_table_1 PARTITION OF parted_table FOR VALUES IN (1); CREATE TABLE rules_parted_table_1 PARTITION OF rules_parted_table FOR VALUES IN (1);
CREATE RULE parted_table_insert AS ON INSERT to parted_table CREATE RULE rules_parted_table_insert AS ON INSERT to rules_parted_table
DO INSTEAD INSERT INTO parted_table_1 VALUES (NEW.*); DO INSTEAD INSERT INTO rules_parted_table_1 VALUES (NEW.*);
ALTER RULE parted_table_insert ON parted_table RENAME TO parted_table_insert_redirect; ALTER RULE rules_parted_table_insert ON rules_parted_table RENAME TO rules_parted_table_insert_redirect;
DROP TABLE parted_table; DROP TABLE rules_parted_table;
-- --
-- Test enabling/disabling -- Test enabling/disabling
-- --
......
...@@ -2,15 +2,15 @@ ...@@ -2,15 +2,15 @@
-- SELECT_INTO -- SELECT_INTO
-- --
SELECT * SELECT *
INTO TABLE tmp1 INTO TABLE sitmp1
FROM onek FROM onek
WHERE onek.unique1 < 2; WHERE onek.unique1 < 2;
DROP TABLE tmp1; DROP TABLE sitmp1;
SELECT * SELECT *
INTO TABLE tmp1 INTO TABLE sitmp1
FROM onek2 FROM onek2
WHERE onek2.unique1 < 2; WHERE onek2.unique1 < 2;
DROP TABLE tmp1; DROP TABLE sitmp1;
-- --
-- SELECT INTO and INSERT permission, if owner is not allowed to insert. -- SELECT INTO and INSERT permission, if owner is not allowed to insert.
-- --
......
-- --
-- PARALLEL -- PARALLEL
-- --
create or replace function parallel_restricted(int) returns int as create function sp_parallel_restricted(int) returns int as
$$begin return $1; end$$ language plpgsql parallel restricted; $$begin return $1; end$$ language plpgsql parallel restricted;
-- Serializable isolation would disable parallel query, so explicitly use an -- Serializable isolation would disable parallel query, so explicitly use an
-- arbitrary other level. -- arbitrary other level.
...@@ -122,12 +122,12 @@ select round(avg(aa)), sum(aa) from a_star a4; ...@@ -122,12 +122,12 @@ select round(avg(aa)), sum(aa) from a_star a4;
reset enable_parallel_append; reset enable_parallel_append;
-- Parallel Append that runs serially -- Parallel Append that runs serially
create or replace function foobar() returns setof text as create function sp_test_func() returns setof text as
$$ select 'foo'::varchar union all select 'bar'::varchar $$ $$ select 'foo'::varchar union all select 'bar'::varchar $$
language sql stable; language sql stable;
select foobar() order by 1; select sp_test_func() order by 1;
foobar sp_test_func
-------- --------------
bar bar
foo foo
(2 rows) (2 rows)
...@@ -178,15 +178,15 @@ reset parallel_leader_participation; ...@@ -178,15 +178,15 @@ reset parallel_leader_participation;
-- test that parallel_restricted function doesn't run in worker -- test that parallel_restricted function doesn't run in worker
alter table tenk1 set (parallel_workers = 4); alter table tenk1 set (parallel_workers = 4);
explain (verbose, costs off) explain (verbose, costs off)
select parallel_restricted(unique1) from tenk1 select sp_parallel_restricted(unique1) from tenk1
where stringu1 = 'GRAAAA' order by 1; where stringu1 = 'GRAAAA' order by 1;
QUERY PLAN QUERY PLAN
--------------------------------------------------------- ---------------------------------------------------------
Sort Sort
Output: (parallel_restricted(unique1)) Output: (sp_parallel_restricted(unique1))
Sort Key: (parallel_restricted(tenk1.unique1)) Sort Key: (sp_parallel_restricted(tenk1.unique1))
-> Gather -> Gather
Output: parallel_restricted(unique1) Output: sp_parallel_restricted(unique1)
Workers Planned: 4 Workers Planned: 4
-> Parallel Seq Scan on public.tenk1 -> Parallel Seq Scan on public.tenk1
Output: unique1 Output: unique1
...@@ -231,12 +231,12 @@ explain (costs off) ...@@ -231,12 +231,12 @@ explain (costs off)
-- test that parallel plan for aggregates is not selected when -- test that parallel plan for aggregates is not selected when
-- target list contains parallel restricted clause. -- target list contains parallel restricted clause.
explain (costs off) explain (costs off)
select sum(parallel_restricted(unique1)) from tenk1 select sum(sp_parallel_restricted(unique1)) from tenk1
group by(parallel_restricted(unique1)); group by(sp_parallel_restricted(unique1));
QUERY PLAN QUERY PLAN
------------------------------------------------------------------- -------------------------------------------------------------------
HashAggregate HashAggregate
Group Key: parallel_restricted(unique1) Group Key: sp_parallel_restricted(unique1)
-> Gather -> Gather
Workers Planned: 4 Workers Planned: 4
-> Parallel Index Only Scan using tenk1_unique1 on tenk1 -> Parallel Index Only Scan using tenk1_unique1 on tenk1
...@@ -609,21 +609,21 @@ select count(*) from tenk1 group by twenty; ...@@ -609,21 +609,21 @@ select count(*) from tenk1 group by twenty;
(20 rows) (20 rows)
--test expressions in targetlist are pushed down for gather merge --test expressions in targetlist are pushed down for gather merge
create or replace function simple_func(var1 integer) returns integer create function sp_simple_func(var1 integer) returns integer
as $$ as $$
begin begin
return var1 + 10; return var1 + 10;
end; end;
$$ language plpgsql PARALLEL SAFE; $$ language plpgsql PARALLEL SAFE;
explain (costs off, verbose) explain (costs off, verbose)
select ten, simple_func(ten) from tenk1 where ten < 100 order by ten; select ten, sp_simple_func(ten) from tenk1 where ten < 100 order by ten;
QUERY PLAN QUERY PLAN
----------------------------------------------------- -----------------------------------------------------
Gather Merge Gather Merge
Output: ten, (simple_func(ten)) Output: ten, (sp_simple_func(ten))
Workers Planned: 4 Workers Planned: 4
-> Result -> Result
Output: ten, simple_func(ten) Output: ten, sp_simple_func(ten)
-> Sort -> Sort
Output: ten Output: ten
Sort Key: tenk1.ten Sort Key: tenk1.ten
...@@ -632,7 +632,7 @@ explain (costs off, verbose) ...@@ -632,7 +632,7 @@ explain (costs off, verbose)
Filter: (tenk1.ten < 100) Filter: (tenk1.ten < 100)
(11 rows) (11 rows)
drop function simple_func(integer); drop function sp_simple_func(integer);
-- test gather merge with parallel leader participation disabled -- test gather merge with parallel leader participation disabled
set parallel_leader_participation = off; set parallel_leader_participation = off;
explain (costs off) explain (costs off)
...@@ -827,7 +827,7 @@ explain (costs off) ...@@ -827,7 +827,7 @@ explain (costs off)
ROLLBACK TO SAVEPOINT settings; ROLLBACK TO SAVEPOINT settings;
-- exercise record typmod remapping between backends -- exercise record typmod remapping between backends
CREATE OR REPLACE FUNCTION make_record(n int) CREATE FUNCTION make_record(n int)
RETURNS RECORD LANGUAGE plpgsql PARALLEL SAFE AS RETURNS RECORD LANGUAGE plpgsql PARALLEL SAFE AS
$$ $$
BEGIN BEGIN
......
...@@ -146,69 +146,69 @@ COMMIT; ...@@ -146,69 +146,69 @@ COMMIT;
-- Subtransactions, basic tests -- Subtransactions, basic tests
-- create & drop tables -- create & drop tables
SET SESSION CHARACTERISTICS AS TRANSACTION READ WRITE; SET SESSION CHARACTERISTICS AS TRANSACTION READ WRITE;
CREATE TABLE foobar (a int); CREATE TABLE trans_foobar (a int);
BEGIN; BEGIN;
CREATE TABLE foo (a int); CREATE TABLE trans_foo (a int);
SAVEPOINT one; SAVEPOINT one;
DROP TABLE foo; DROP TABLE trans_foo;
CREATE TABLE bar (a int); CREATE TABLE trans_bar (a int);
ROLLBACK TO SAVEPOINT one; ROLLBACK TO SAVEPOINT one;
RELEASE SAVEPOINT one; RELEASE SAVEPOINT one;
SAVEPOINT two; SAVEPOINT two;
CREATE TABLE baz (a int); CREATE TABLE trans_baz (a int);
RELEASE SAVEPOINT two; RELEASE SAVEPOINT two;
drop TABLE foobar; drop TABLE trans_foobar;
CREATE TABLE barbaz (a int); CREATE TABLE trans_barbaz (a int);
COMMIT; COMMIT;
-- should exist: barbaz, baz, foo -- should exist: trans_barbaz, trans_baz, trans_foo
SELECT * FROM foo; -- should be empty SELECT * FROM trans_foo; -- should be empty
a a
--- ---
(0 rows) (0 rows)
SELECT * FROM bar; -- shouldn't exist SELECT * FROM trans_bar; -- shouldn't exist
ERROR: relation "bar" does not exist ERROR: relation "trans_bar" does not exist
LINE 1: SELECT * FROM bar; LINE 1: SELECT * FROM trans_bar;
^ ^
SELECT * FROM barbaz; -- should be empty SELECT * FROM trans_barbaz; -- should be empty
a a
--- ---
(0 rows) (0 rows)
SELECT * FROM baz; -- should be empty SELECT * FROM trans_baz; -- should be empty
a a
--- ---
(0 rows) (0 rows)
-- inserts -- inserts
BEGIN; BEGIN;
INSERT INTO foo VALUES (1); INSERT INTO trans_foo VALUES (1);
SAVEPOINT one; SAVEPOINT one;
INSERT into bar VALUES (1); INSERT into trans_bar VALUES (1);
ERROR: relation "bar" does not exist ERROR: relation "trans_bar" does not exist
LINE 1: INSERT into bar VALUES (1); LINE 1: INSERT into trans_bar VALUES (1);
^ ^
ROLLBACK TO one; ROLLBACK TO one;
RELEASE SAVEPOINT one; RELEASE SAVEPOINT one;
SAVEPOINT two; SAVEPOINT two;
INSERT into barbaz VALUES (1); INSERT into trans_barbaz VALUES (1);
RELEASE two; RELEASE two;
SAVEPOINT three; SAVEPOINT three;
SAVEPOINT four; SAVEPOINT four;
INSERT INTO foo VALUES (2); INSERT INTO trans_foo VALUES (2);
RELEASE SAVEPOINT four; RELEASE SAVEPOINT four;
ROLLBACK TO SAVEPOINT three; ROLLBACK TO SAVEPOINT three;
RELEASE SAVEPOINT three; RELEASE SAVEPOINT three;
INSERT INTO foo VALUES (3); INSERT INTO trans_foo VALUES (3);
COMMIT; COMMIT;
SELECT * FROM foo; -- should have 1 and 3 SELECT * FROM trans_foo; -- should have 1 and 3
a a
--- ---
1 1
3 3
(2 rows) (2 rows)
SELECT * FROM barbaz; -- should have 1 SELECT * FROM trans_barbaz; -- should have 1
a a
--- ---
1 1
...@@ -217,9 +217,9 @@ SELECT * FROM barbaz; -- should have 1 ...@@ -217,9 +217,9 @@ SELECT * FROM barbaz; -- should have 1
-- test whole-tree commit -- test whole-tree commit
BEGIN; BEGIN;
SAVEPOINT one; SAVEPOINT one;
SELECT foo; SELECT trans_foo;
ERROR: column "foo" does not exist ERROR: column "trans_foo" does not exist
LINE 1: SELECT foo; LINE 1: SELECT trans_foo;
^ ^
ROLLBACK TO SAVEPOINT one; ROLLBACK TO SAVEPOINT one;
RELEASE SAVEPOINT one; RELEASE SAVEPOINT one;
...@@ -266,9 +266,9 @@ BEGIN; ...@@ -266,9 +266,9 @@ BEGIN;
INSERT INTO savepoints VALUES (4); INSERT INTO savepoints VALUES (4);
SAVEPOINT one; SAVEPOINT one;
INSERT INTO savepoints VALUES (5); INSERT INTO savepoints VALUES (5);
SELECT foo; SELECT trans_foo;
ERROR: column "foo" does not exist ERROR: column "trans_foo" does not exist
LINE 1: SELECT foo; LINE 1: SELECT trans_foo;
^ ^
COMMIT; COMMIT;
SELECT * FROM savepoints; SELECT * FROM savepoints;
...@@ -549,9 +549,9 @@ DETAIL: Key (a)=(1) already exists. ...@@ -549,9 +549,9 @@ DETAIL: Key (a)=(1) already exists.
ERROR: duplicate key value violates unique constraint "koju_a_key" ERROR: duplicate key value violates unique constraint "koju_a_key"
DETAIL: Key (a)=(1) already exists. DETAIL: Key (a)=(1) already exists.
ROLLBACK; ROLLBACK;
DROP TABLE foo; DROP TABLE trans_foo;
DROP TABLE baz; DROP TABLE trans_baz;
DROP TABLE barbaz; DROP TABLE trans_barbaz;
-- test case for problems with revalidating an open relation during abort -- test case for problems with revalidating an open relation during abort
create function inverse(int) returns float8 as create function inverse(int) returns float8 as
$$ $$
......
...@@ -23,8 +23,8 @@ CREATE VIEW rw_view15 AS SELECT a, upper(b) FROM base_tbl; -- Expression/functio ...@@ -23,8 +23,8 @@ CREATE VIEW rw_view15 AS SELECT a, upper(b) FROM base_tbl; -- Expression/functio
CREATE VIEW rw_view16 AS SELECT a, b, a AS aa FROM base_tbl; -- Repeated column may be part of an updatable view CREATE VIEW rw_view16 AS SELECT a, b, a AS aa FROM base_tbl; -- Repeated column may be part of an updatable view
CREATE VIEW ro_view17 AS SELECT * FROM ro_view1; -- Base relation not updatable CREATE VIEW ro_view17 AS SELECT * FROM ro_view1; -- Base relation not updatable
CREATE VIEW ro_view18 AS SELECT * FROM (VALUES(1)) AS tmp(a); -- VALUES in rangetable CREATE VIEW ro_view18 AS SELECT * FROM (VALUES(1)) AS tmp(a); -- VALUES in rangetable
CREATE SEQUENCE seq; CREATE SEQUENCE uv_seq;
CREATE VIEW ro_view19 AS SELECT * FROM seq; -- View based on a sequence CREATE VIEW ro_view19 AS SELECT * FROM uv_seq; -- View based on a sequence
CREATE VIEW ro_view20 AS SELECT a, b, generate_series(1, a) g FROM base_tbl; -- SRF in targetlist not supported CREATE VIEW ro_view20 AS SELECT a, b, generate_series(1, a) g FROM base_tbl; -- SRF in targetlist not supported
SELECT table_name, is_insertable_into SELECT table_name, is_insertable_into
FROM information_schema.tables FROM information_schema.tables
...@@ -347,7 +347,7 @@ drop cascades to view ro_view20 ...@@ -347,7 +347,7 @@ drop cascades to view ro_view20
drop cascades to view ro_view4 drop cascades to view ro_view4
drop cascades to view rw_view14 drop cascades to view rw_view14
DROP VIEW ro_view10, ro_view12, ro_view18; DROP VIEW ro_view10, ro_view12, ro_view18;
DROP SEQUENCE seq CASCADE; DROP SEQUENCE uv_seq CASCADE;
NOTICE: drop cascades to view ro_view19 NOTICE: drop cascades to view ro_view19
-- simple updatable view -- simple updatable view
CREATE TABLE base_tbl (a int PRIMARY KEY, b text DEFAULT 'Unspecified'); CREATE TABLE base_tbl (a int PRIMARY KEY, b text DEFAULT 'Unspecified');
...@@ -2368,66 +2368,66 @@ DETAIL: Failing row contains (-1, invalid). ...@@ -2368,66 +2368,66 @@ DETAIL: Failing row contains (-1, invalid).
DROP VIEW v1; DROP VIEW v1;
DROP TABLE t1; DROP TABLE t1;
-- check that an auto-updatable view on a partitioned table works correctly -- check that an auto-updatable view on a partitioned table works correctly
create table pt (a int, b int, v varchar) partition by range (a, b); create table uv_pt (a int, b int, v varchar) partition by range (a, b);
create table pt1 (b int not null, v varchar, a int not null) partition by range (b); create table uv_pt1 (b int not null, v varchar, a int not null) partition by range (b);
create table pt11 (like pt1); create table uv_pt11 (like uv_pt1);
alter table pt11 drop a; alter table uv_pt11 drop a;
alter table pt11 add a int; alter table uv_pt11 add a int;
alter table pt11 drop a; alter table uv_pt11 drop a;
alter table pt11 add a int not null; alter table uv_pt11 add a int not null;
alter table pt1 attach partition pt11 for values from (2) to (5); alter table uv_pt1 attach partition uv_pt11 for values from (2) to (5);
alter table pt attach partition pt1 for values from (1, 2) to (1, 10); alter table uv_pt attach partition uv_pt1 for values from (1, 2) to (1, 10);
create view ptv as select * from pt; create view uv_ptv as select * from uv_pt;
select events & 4 != 0 AS upd, select events & 4 != 0 AS upd,
events & 8 != 0 AS ins, events & 8 != 0 AS ins,
events & 16 != 0 AS del events & 16 != 0 AS del
from pg_catalog.pg_relation_is_updatable('pt'::regclass, false) t(events); from pg_catalog.pg_relation_is_updatable('uv_pt'::regclass, false) t(events);
upd | ins | del upd | ins | del
-----+-----+----- -----+-----+-----
t | t | t t | t | t
(1 row) (1 row)
select pg_catalog.pg_column_is_updatable('pt'::regclass, 1::smallint, false); select pg_catalog.pg_column_is_updatable('uv_pt'::regclass, 1::smallint, false);
pg_column_is_updatable pg_column_is_updatable
------------------------ ------------------------
t t
(1 row) (1 row)
select pg_catalog.pg_column_is_updatable('pt'::regclass, 2::smallint, false); select pg_catalog.pg_column_is_updatable('uv_pt'::regclass, 2::smallint, false);
pg_column_is_updatable pg_column_is_updatable
------------------------ ------------------------
t t
(1 row) (1 row)
select table_name, is_updatable, is_insertable_into select table_name, is_updatable, is_insertable_into
from information_schema.views where table_name = 'ptv'; from information_schema.views where table_name = 'uv_ptv';
table_name | is_updatable | is_insertable_into table_name | is_updatable | is_insertable_into
------------+--------------+-------------------- ------------+--------------+--------------------
ptv | YES | YES uv_ptv | YES | YES
(1 row) (1 row)
select table_name, column_name, is_updatable select table_name, column_name, is_updatable
from information_schema.columns where table_name = 'ptv' order by column_name; from information_schema.columns where table_name = 'uv_ptv' order by column_name;
table_name | column_name | is_updatable table_name | column_name | is_updatable
------------+-------------+-------------- ------------+-------------+--------------
ptv | a | YES uv_ptv | a | YES
ptv | b | YES uv_ptv | b | YES
ptv | v | YES uv_ptv | v | YES
(3 rows) (3 rows)
insert into ptv values (1, 2); insert into uv_ptv values (1, 2);
select tableoid::regclass, * from pt; select tableoid::regclass, * from uv_pt;
tableoid | a | b | v tableoid | a | b | v
----------+---+---+--- ----------+---+---+---
pt11 | 1 | 2 | uv_pt11 | 1 | 2 |
(1 row) (1 row)
create view ptv_wco as select * from pt where a = 0 with check option; create view uv_ptv_wco as select * from uv_pt where a = 0 with check option;
insert into ptv_wco values (1, 2); insert into uv_ptv_wco values (1, 2);
ERROR: new row violates check option for view "ptv_wco" ERROR: new row violates check option for view "uv_ptv_wco"
DETAIL: Failing row contains (1, 2, null). DETAIL: Failing row contains (1, 2, null).
drop view ptv, ptv_wco; drop view uv_ptv, uv_ptv_wco;
drop table pt, pt1, pt11; drop table uv_pt, uv_pt1, uv_pt11;
-- check that wholerow vars appearing in WITH CHECK OPTION constraint expressions -- check that wholerow vars appearing in WITH CHECK OPTION constraint expressions
-- work fine with partitioned tables -- work fine with partitioned tables
create table wcowrtest (a int) partition by list (a); create table wcowrtest (a int) partition by list (a);
......
...@@ -1819,12 +1819,12 @@ SELECT * FROM y; ...@@ -1819,12 +1819,12 @@ SELECT * FROM y;
(22 rows) (22 rows)
-- data-modifying WITH containing INSERT...ON CONFLICT DO UPDATE -- data-modifying WITH containing INSERT...ON CONFLICT DO UPDATE
CREATE TABLE z AS SELECT i AS k, (i || ' v')::text v FROM generate_series(1, 16, 3) i; CREATE TABLE withz AS SELECT i AS k, (i || ' v')::text v FROM generate_series(1, 16, 3) i;
ALTER TABLE z ADD UNIQUE (k); ALTER TABLE withz ADD UNIQUE (k);
WITH t AS ( WITH t AS (
INSERT INTO z SELECT i, 'insert' INSERT INTO withz SELECT i, 'insert'
FROM generate_series(0, 16) i FROM generate_series(0, 16) i
ON CONFLICT (k) DO UPDATE SET v = z.v || ', now update' ON CONFLICT (k) DO UPDATE SET v = withz.v || ', now update'
RETURNING * RETURNING *
) )
SELECT * FROM t JOIN y ON t.k = y.a ORDER BY a, k; SELECT * FROM t JOIN y ON t.k = y.a ORDER BY a, k;
...@@ -1836,8 +1836,8 @@ SELECT * FROM t JOIN y ON t.k = y.a ORDER BY a, k; ...@@ -1836,8 +1836,8 @@ SELECT * FROM t JOIN y ON t.k = y.a ORDER BY a, k;
-- Test EXCLUDED.* reference within CTE -- Test EXCLUDED.* reference within CTE
WITH aa AS ( WITH aa AS (
INSERT INTO z VALUES(1, 5) ON CONFLICT (k) DO UPDATE SET v = EXCLUDED.v INSERT INTO withz VALUES(1, 5) ON CONFLICT (k) DO UPDATE SET v = EXCLUDED.v
WHERE z.k != EXCLUDED.k WHERE withz.k != EXCLUDED.k
RETURNING * RETURNING *
) )
SELECT * FROM aa; SELECT * FROM aa;
...@@ -1846,7 +1846,7 @@ SELECT * FROM aa; ...@@ -1846,7 +1846,7 @@ SELECT * FROM aa;
(0 rows) (0 rows)
-- New query/snapshot demonstrates side-effects of previous query. -- New query/snapshot demonstrates side-effects of previous query.
SELECT * FROM z ORDER BY k; SELECT * FROM withz ORDER BY k;
k | v k | v
----+------------------ ----+------------------
0 | insert 0 | insert
...@@ -1873,19 +1873,19 @@ SELECT * FROM z ORDER BY k; ...@@ -1873,19 +1873,19 @@ SELECT * FROM z ORDER BY k;
-- reference outside values -- reference outside values
-- --
WITH aa AS (SELECT 1 a, 2 b) WITH aa AS (SELECT 1 a, 2 b)
INSERT INTO z VALUES(1, 'insert') INSERT INTO withz VALUES(1, 'insert')
ON CONFLICT (k) DO UPDATE SET v = (SELECT b || ' update' FROM aa WHERE a = 1 LIMIT 1); ON CONFLICT (k) DO UPDATE SET v = (SELECT b || ' update' FROM aa WHERE a = 1 LIMIT 1);
WITH aa AS (SELECT 1 a, 2 b) WITH aa AS (SELECT 1 a, 2 b)
INSERT INTO z VALUES(1, 'insert') INSERT INTO withz VALUES(1, 'insert')
ON CONFLICT (k) DO UPDATE SET v = ' update' WHERE z.k = (SELECT a FROM aa); ON CONFLICT (k) DO UPDATE SET v = ' update' WHERE withz.k = (SELECT a FROM aa);
WITH aa AS (SELECT 1 a, 2 b) WITH aa AS (SELECT 1 a, 2 b)
INSERT INTO z VALUES(1, 'insert') INSERT INTO withz VALUES(1, 'insert')
ON CONFLICT (k) DO UPDATE SET v = (SELECT b || ' update' FROM aa WHERE a = 1 LIMIT 1); ON CONFLICT (k) DO UPDATE SET v = (SELECT b || ' update' FROM aa WHERE a = 1 LIMIT 1);
WITH aa AS (SELECT 'a' a, 'b' b UNION ALL SELECT 'a' a, 'b' b) WITH aa AS (SELECT 'a' a, 'b' b UNION ALL SELECT 'a' a, 'b' b)
INSERT INTO z VALUES(1, 'insert') INSERT INTO withz VALUES(1, 'insert')
ON CONFLICT (k) DO UPDATE SET v = (SELECT b || ' update' FROM aa WHERE a = 'a' LIMIT 1); ON CONFLICT (k) DO UPDATE SET v = (SELECT b || ' update' FROM aa WHERE a = 'a' LIMIT 1);
WITH aa AS (SELECT 1 a, 2 b) WITH aa AS (SELECT 1 a, 2 b)
INSERT INTO z VALUES(1, (SELECT b || ' insert' FROM aa WHERE a = 1 )) INSERT INTO withz VALUES(1, (SELECT b || ' insert' FROM aa WHERE a = 1 ))
ON CONFLICT (k) DO UPDATE SET v = (SELECT b || ' update' FROM aa WHERE a = 1 LIMIT 1); ON CONFLICT (k) DO UPDATE SET v = (SELECT b || ' update' FROM aa WHERE a = 1 LIMIT 1);
-- Update a row more than once, in different parts of a wCTE. That is -- Update a row more than once, in different parts of a wCTE. That is
-- an allowed, presumably very rare, edge case, but since it was -- an allowed, presumably very rare, edge case, but since it was
...@@ -1893,17 +1893,17 @@ ON CONFLICT (k) DO UPDATE SET v = (SELECT b || ' update' FROM aa WHERE a = 1 LIM ...@@ -1893,17 +1893,17 @@ ON CONFLICT (k) DO UPDATE SET v = (SELECT b || ' update' FROM aa WHERE a = 1 LIM
WITH simpletup AS ( WITH simpletup AS (
SELECT 2 k, 'Green' v), SELECT 2 k, 'Green' v),
upsert_cte AS ( upsert_cte AS (
INSERT INTO z VALUES(2, 'Blue') ON CONFLICT (k) DO INSERT INTO withz VALUES(2, 'Blue') ON CONFLICT (k) DO
UPDATE SET (k, v) = (SELECT k, v FROM simpletup WHERE simpletup.k = z.k) UPDATE SET (k, v) = (SELECT k, v FROM simpletup WHERE simpletup.k = withz.k)
RETURNING k, v) RETURNING k, v)
INSERT INTO z VALUES(2, 'Red') ON CONFLICT (k) DO INSERT INTO withz VALUES(2, 'Red') ON CONFLICT (k) DO
UPDATE SET (k, v) = (SELECT k, v FROM upsert_cte WHERE upsert_cte.k = z.k) UPDATE SET (k, v) = (SELECT k, v FROM upsert_cte WHERE upsert_cte.k = withz.k)
RETURNING k, v; RETURNING k, v;
k | v k | v
---+--- ---+---
(0 rows) (0 rows)
DROP TABLE z; DROP TABLE withz;
-- check that run to completion happens in proper ordering -- check that run to completion happens in proper ordering
TRUNCATE TABLE y; TRUNCATE TABLE y;
INSERT INTO y SELECT generate_series(1, 3); INSERT INTO y SELECT generate_series(1, 3);
...@@ -2280,7 +2280,7 @@ LINE 1: WITH test AS (SELECT 42) INSERT INTO test VALUES (1); ...@@ -2280,7 +2280,7 @@ LINE 1: WITH test AS (SELECT 42) INSERT INTO test VALUES (1);
-- check response to attempt to modify table with same name as a CTE (perhaps -- check response to attempt to modify table with same name as a CTE (perhaps
-- surprisingly it works, because CTEs don't hide tables from data-modifying -- surprisingly it works, because CTEs don't hide tables from data-modifying
-- statements) -- statements)
create table test (i int); create temp table test (i int);
with test as (select 42) insert into test select * from test; with test as (select 42) insert into test select * from test;
select * from test; select * from test;
i i
......
This diff is collapsed.
CALL nonexistent(); -- error CALL nonexistent(); -- error
CALL random(); -- error CALL random(); -- error
CREATE FUNCTION testfunc1(a int) RETURNS int LANGUAGE SQL AS $$ SELECT a $$; CREATE FUNCTION cp_testfunc1(a int) RETURNS int LANGUAGE SQL AS $$ SELECT a $$;
CREATE TABLE cp_test (a int, b text); CREATE TABLE cp_test (a int, b text);
...@@ -76,11 +76,11 @@ CREATE PROCEDURE ptestx(OUT a int) LANGUAGE SQL AS $$ INSERT INTO cp_test VALUES ...@@ -76,11 +76,11 @@ CREATE PROCEDURE ptestx(OUT a int) LANGUAGE SQL AS $$ INSERT INTO cp_test VALUES
ALTER PROCEDURE ptest1(text) STRICT; ALTER PROCEDURE ptest1(text) STRICT;
ALTER FUNCTION ptest1(text) VOLATILE; -- error: not a function ALTER FUNCTION ptest1(text) VOLATILE; -- error: not a function
ALTER PROCEDURE testfunc1(int) VOLATILE; -- error: not a procedure ALTER PROCEDURE cp_testfunc1(int) VOLATILE; -- error: not a procedure
ALTER PROCEDURE nonexistent() VOLATILE; ALTER PROCEDURE nonexistent() VOLATILE;
DROP FUNCTION ptest1(text); -- error: not a function DROP FUNCTION ptest1(text); -- error: not a function
DROP PROCEDURE testfunc1(int); -- error: not a procedure DROP PROCEDURE cp_testfunc1(int); -- error: not a procedure
DROP PROCEDURE nonexistent(); DROP PROCEDURE nonexistent();
...@@ -100,13 +100,13 @@ RESET ROLE; ...@@ -100,13 +100,13 @@ RESET ROLE;
-- ROUTINE syntax -- ROUTINE syntax
ALTER ROUTINE testfunc1(int) RENAME TO testfunc1a; ALTER ROUTINE cp_testfunc1(int) RENAME TO cp_testfunc1a;
ALTER ROUTINE testfunc1a RENAME TO testfunc1; ALTER ROUTINE cp_testfunc1a RENAME TO cp_testfunc1;
ALTER ROUTINE ptest1(text) RENAME TO ptest1a; ALTER ROUTINE ptest1(text) RENAME TO ptest1a;
ALTER ROUTINE ptest1a RENAME TO ptest1; ALTER ROUTINE ptest1a RENAME TO ptest1;
DROP ROUTINE testfunc1(int); DROP ROUTINE cp_testfunc1(int);
-- cleanup -- cleanup
......
...@@ -579,25 +579,25 @@ DROP TRIGGER trigtest_after_row ON foreign_schema.foreign_table_1; ...@@ -579,25 +579,25 @@ DROP TRIGGER trigtest_after_row ON foreign_schema.foreign_table_1;
DROP FUNCTION dummy_trigger(); DROP FUNCTION dummy_trigger();
-- Table inheritance -- Table inheritance
CREATE TABLE pt1 ( CREATE TABLE fd_pt1 (
c1 integer NOT NULL, c1 integer NOT NULL,
c2 text, c2 text,
c3 date c3 date
); );
CREATE FOREIGN TABLE ft2 () INHERITS (pt1) CREATE FOREIGN TABLE ft2 () INHERITS (fd_pt1)
SERVER s0 OPTIONS (delimiter ',', quote '"', "be quoted" 'value'); SERVER s0 OPTIONS (delimiter ',', quote '"', "be quoted" 'value');
\d+ pt1 \d+ fd_pt1
\d+ ft2 \d+ ft2
DROP FOREIGN TABLE ft2; DROP FOREIGN TABLE ft2;
\d+ pt1 \d+ fd_pt1
CREATE FOREIGN TABLE ft2 ( CREATE FOREIGN TABLE ft2 (
c1 integer NOT NULL, c1 integer NOT NULL,
c2 text, c2 text,
c3 date c3 date
) SERVER s0 OPTIONS (delimiter ',', quote '"', "be quoted" 'value'); ) SERVER s0 OPTIONS (delimiter ',', quote '"', "be quoted" 'value');
\d+ ft2 \d+ ft2
ALTER FOREIGN TABLE ft2 INHERIT pt1; ALTER FOREIGN TABLE ft2 INHERIT fd_pt1;
\d+ pt1 \d+ fd_pt1
\d+ ft2 \d+ ft2
CREATE TABLE ct3() INHERITS(ft2); CREATE TABLE ct3() INHERITS(ft2);
CREATE FOREIGN TABLE ft3 ( CREATE FOREIGN TABLE ft3 (
...@@ -611,50 +611,50 @@ CREATE FOREIGN TABLE ft3 ( ...@@ -611,50 +611,50 @@ CREATE FOREIGN TABLE ft3 (
\d+ ft3 \d+ ft3
-- add attributes recursively -- add attributes recursively
ALTER TABLE pt1 ADD COLUMN c4 integer; ALTER TABLE fd_pt1 ADD COLUMN c4 integer;
ALTER TABLE pt1 ADD COLUMN c5 integer DEFAULT 0; ALTER TABLE fd_pt1 ADD COLUMN c5 integer DEFAULT 0;
ALTER TABLE pt1 ADD COLUMN c6 integer; ALTER TABLE fd_pt1 ADD COLUMN c6 integer;
ALTER TABLE pt1 ADD COLUMN c7 integer NOT NULL; ALTER TABLE fd_pt1 ADD COLUMN c7 integer NOT NULL;
ALTER TABLE pt1 ADD COLUMN c8 integer; ALTER TABLE fd_pt1 ADD COLUMN c8 integer;
\d+ pt1 \d+ fd_pt1
\d+ ft2 \d+ ft2
\d+ ct3 \d+ ct3
\d+ ft3 \d+ ft3
-- alter attributes recursively -- alter attributes recursively
ALTER TABLE pt1 ALTER COLUMN c4 SET DEFAULT 0; ALTER TABLE fd_pt1 ALTER COLUMN c4 SET DEFAULT 0;
ALTER TABLE pt1 ALTER COLUMN c5 DROP DEFAULT; ALTER TABLE fd_pt1 ALTER COLUMN c5 DROP DEFAULT;
ALTER TABLE pt1 ALTER COLUMN c6 SET NOT NULL; ALTER TABLE fd_pt1 ALTER COLUMN c6 SET NOT NULL;
ALTER TABLE pt1 ALTER COLUMN c7 DROP NOT NULL; ALTER TABLE fd_pt1 ALTER COLUMN c7 DROP NOT NULL;
ALTER TABLE pt1 ALTER COLUMN c8 TYPE char(10) USING '0'; -- ERROR ALTER TABLE fd_pt1 ALTER COLUMN c8 TYPE char(10) USING '0'; -- ERROR
ALTER TABLE pt1 ALTER COLUMN c8 TYPE char(10); ALTER TABLE fd_pt1 ALTER COLUMN c8 TYPE char(10);
ALTER TABLE pt1 ALTER COLUMN c8 SET DATA TYPE text; ALTER TABLE fd_pt1 ALTER COLUMN c8 SET DATA TYPE text;
ALTER TABLE pt1 ALTER COLUMN c1 SET STATISTICS 10000; ALTER TABLE fd_pt1 ALTER COLUMN c1 SET STATISTICS 10000;
ALTER TABLE pt1 ALTER COLUMN c1 SET (n_distinct = 100); ALTER TABLE fd_pt1 ALTER COLUMN c1 SET (n_distinct = 100);
ALTER TABLE pt1 ALTER COLUMN c8 SET STATISTICS -1; ALTER TABLE fd_pt1 ALTER COLUMN c8 SET STATISTICS -1;
ALTER TABLE pt1 ALTER COLUMN c8 SET STORAGE EXTERNAL; ALTER TABLE fd_pt1 ALTER COLUMN c8 SET STORAGE EXTERNAL;
\d+ pt1 \d+ fd_pt1
\d+ ft2 \d+ ft2
-- drop attributes recursively -- drop attributes recursively
ALTER TABLE pt1 DROP COLUMN c4; ALTER TABLE fd_pt1 DROP COLUMN c4;
ALTER TABLE pt1 DROP COLUMN c5; ALTER TABLE fd_pt1 DROP COLUMN c5;
ALTER TABLE pt1 DROP COLUMN c6; ALTER TABLE fd_pt1 DROP COLUMN c6;
ALTER TABLE pt1 DROP COLUMN c7; ALTER TABLE fd_pt1 DROP COLUMN c7;
ALTER TABLE pt1 DROP COLUMN c8; ALTER TABLE fd_pt1 DROP COLUMN c8;
\d+ pt1 \d+ fd_pt1
\d+ ft2 \d+ ft2
-- add constraints recursively -- add constraints recursively
ALTER TABLE pt1 ADD CONSTRAINT pt1chk1 CHECK (c1 > 0) NO INHERIT; ALTER TABLE fd_pt1 ADD CONSTRAINT fd_pt1chk1 CHECK (c1 > 0) NO INHERIT;
ALTER TABLE pt1 ADD CONSTRAINT pt1chk2 CHECK (c2 <> ''); ALTER TABLE fd_pt1 ADD CONSTRAINT fd_pt1chk2 CHECK (c2 <> '');
-- connoinherit should be true for NO INHERIT constraint -- connoinherit should be true for NO INHERIT constraint
SELECT relname, conname, contype, conislocal, coninhcount, connoinherit SELECT relname, conname, contype, conislocal, coninhcount, connoinherit
FROM pg_class AS pc JOIN pg_constraint AS pgc ON (conrelid = pc.oid) FROM pg_class AS pc JOIN pg_constraint AS pgc ON (conrelid = pc.oid)
WHERE pc.relname = 'pt1' WHERE pc.relname = 'fd_pt1'
ORDER BY 1,2; ORDER BY 1,2;
-- child does not inherit NO INHERIT constraints -- child does not inherit NO INHERIT constraints
\d+ pt1 \d+ fd_pt1
\d+ ft2 \d+ ft2
\set VERBOSITY terse \set VERBOSITY terse
DROP FOREIGN TABLE ft2; -- ERROR DROP FOREIGN TABLE ft2; -- ERROR
...@@ -666,50 +666,50 @@ CREATE FOREIGN TABLE ft2 ( ...@@ -666,50 +666,50 @@ CREATE FOREIGN TABLE ft2 (
c3 date c3 date
) SERVER s0 OPTIONS (delimiter ',', quote '"', "be quoted" 'value'); ) SERVER s0 OPTIONS (delimiter ',', quote '"', "be quoted" 'value');
-- child must have parent's INHERIT constraints -- child must have parent's INHERIT constraints
ALTER FOREIGN TABLE ft2 INHERIT pt1; -- ERROR ALTER FOREIGN TABLE ft2 INHERIT fd_pt1; -- ERROR
ALTER FOREIGN TABLE ft2 ADD CONSTRAINT pt1chk2 CHECK (c2 <> ''); ALTER FOREIGN TABLE ft2 ADD CONSTRAINT fd_pt1chk2 CHECK (c2 <> '');
ALTER FOREIGN TABLE ft2 INHERIT pt1; ALTER FOREIGN TABLE ft2 INHERIT fd_pt1;
-- child does not inherit NO INHERIT constraints -- child does not inherit NO INHERIT constraints
\d+ pt1 \d+ fd_pt1
\d+ ft2 \d+ ft2
-- drop constraints recursively -- drop constraints recursively
ALTER TABLE pt1 DROP CONSTRAINT pt1chk1 CASCADE; ALTER TABLE fd_pt1 DROP CONSTRAINT fd_pt1chk1 CASCADE;
ALTER TABLE pt1 DROP CONSTRAINT pt1chk2 CASCADE; ALTER TABLE fd_pt1 DROP CONSTRAINT fd_pt1chk2 CASCADE;
-- NOT VALID case -- NOT VALID case
INSERT INTO pt1 VALUES (1, 'pt1'::text, '1994-01-01'::date); INSERT INTO fd_pt1 VALUES (1, 'fd_pt1'::text, '1994-01-01'::date);
ALTER TABLE pt1 ADD CONSTRAINT pt1chk3 CHECK (c2 <> '') NOT VALID; ALTER TABLE fd_pt1 ADD CONSTRAINT fd_pt1chk3 CHECK (c2 <> '') NOT VALID;
\d+ pt1 \d+ fd_pt1
\d+ ft2 \d+ ft2
-- VALIDATE CONSTRAINT need do nothing on foreign tables -- VALIDATE CONSTRAINT need do nothing on foreign tables
ALTER TABLE pt1 VALIDATE CONSTRAINT pt1chk3; ALTER TABLE fd_pt1 VALIDATE CONSTRAINT fd_pt1chk3;
\d+ pt1 \d+ fd_pt1
\d+ ft2 \d+ ft2
-- OID system column -- OID system column
ALTER TABLE pt1 SET WITH OIDS; ALTER TABLE fd_pt1 SET WITH OIDS;
\d+ pt1 \d+ fd_pt1
\d+ ft2 \d+ ft2
ALTER TABLE ft2 SET WITHOUT OIDS; -- ERROR ALTER TABLE ft2 SET WITHOUT OIDS; -- ERROR
ALTER TABLE pt1 SET WITHOUT OIDS; ALTER TABLE fd_pt1 SET WITHOUT OIDS;
\d+ pt1 \d+ fd_pt1
\d+ ft2 \d+ ft2
-- changes name of an attribute recursively -- changes name of an attribute recursively
ALTER TABLE pt1 RENAME COLUMN c1 TO f1; ALTER TABLE fd_pt1 RENAME COLUMN c1 TO f1;
ALTER TABLE pt1 RENAME COLUMN c2 TO f2; ALTER TABLE fd_pt1 RENAME COLUMN c2 TO f2;
ALTER TABLE pt1 RENAME COLUMN c3 TO f3; ALTER TABLE fd_pt1 RENAME COLUMN c3 TO f3;
-- changes name of a constraint recursively -- changes name of a constraint recursively
ALTER TABLE pt1 RENAME CONSTRAINT pt1chk3 TO f2_check; ALTER TABLE fd_pt1 RENAME CONSTRAINT fd_pt1chk3 TO f2_check;
\d+ pt1 \d+ fd_pt1
\d+ ft2 \d+ ft2
-- TRUNCATE doesn't work on foreign tables, either directly or recursively -- TRUNCATE doesn't work on foreign tables, either directly or recursively
TRUNCATE ft2; -- ERROR TRUNCATE ft2; -- ERROR
TRUNCATE pt1; -- ERROR TRUNCATE fd_pt1; -- ERROR
DROP TABLE pt1 CASCADE; DROP TABLE fd_pt1 CASCADE;
-- IMPORT FOREIGN SCHEMA -- IMPORT FOREIGN SCHEMA
IMPORT FOREIGN SCHEMA s1 FROM SERVER s9 INTO public; -- ERROR IMPORT FOREIGN SCHEMA s1 FROM SERVER s9 INTO public; -- ERROR
...@@ -729,75 +729,75 @@ DROP OWNED BY regress_test_role2; ...@@ -729,75 +729,75 @@ DROP OWNED BY regress_test_role2;
DROP OWNED BY regress_test_role2 CASCADE; DROP OWNED BY regress_test_role2 CASCADE;
-- Foreign partition DDL stuff -- Foreign partition DDL stuff
CREATE TABLE pt2 ( CREATE TABLE fd_pt2 (
c1 integer NOT NULL, c1 integer NOT NULL,
c2 text, c2 text,
c3 date c3 date
) PARTITION BY LIST (c1); ) PARTITION BY LIST (c1);
CREATE FOREIGN TABLE pt2_1 PARTITION OF pt2 FOR VALUES IN (1) CREATE FOREIGN TABLE fd_pt2_1 PARTITION OF fd_pt2 FOR VALUES IN (1)
SERVER s0 OPTIONS (delimiter ',', quote '"', "be quoted" 'value'); SERVER s0 OPTIONS (delimiter ',', quote '"', "be quoted" 'value');
\d+ pt2 \d+ fd_pt2
\d+ pt2_1 \d+ fd_pt2_1
-- partition cannot have additional columns -- partition cannot have additional columns
DROP FOREIGN TABLE pt2_1; DROP FOREIGN TABLE fd_pt2_1;
CREATE FOREIGN TABLE pt2_1 ( CREATE FOREIGN TABLE fd_pt2_1 (
c1 integer NOT NULL, c1 integer NOT NULL,
c2 text, c2 text,
c3 date, c3 date,
c4 char c4 char
) SERVER s0 OPTIONS (delimiter ',', quote '"', "be quoted" 'value'); ) SERVER s0 OPTIONS (delimiter ',', quote '"', "be quoted" 'value');
\d+ pt2_1 \d+ fd_pt2_1
ALTER TABLE pt2 ATTACH PARTITION pt2_1 FOR VALUES IN (1); -- ERROR ALTER TABLE fd_pt2 ATTACH PARTITION fd_pt2_1 FOR VALUES IN (1); -- ERROR
DROP FOREIGN TABLE pt2_1; DROP FOREIGN TABLE fd_pt2_1;
\d+ pt2 \d+ fd_pt2
CREATE FOREIGN TABLE pt2_1 ( CREATE FOREIGN TABLE fd_pt2_1 (
c1 integer NOT NULL, c1 integer NOT NULL,
c2 text, c2 text,
c3 date c3 date
) SERVER s0 OPTIONS (delimiter ',', quote '"', "be quoted" 'value'); ) SERVER s0 OPTIONS (delimiter ',', quote '"', "be quoted" 'value');
\d+ pt2_1 \d+ fd_pt2_1
-- no attach partition validation occurs for foreign tables -- no attach partition validation occurs for foreign tables
ALTER TABLE pt2 ATTACH PARTITION pt2_1 FOR VALUES IN (1); ALTER TABLE fd_pt2 ATTACH PARTITION fd_pt2_1 FOR VALUES IN (1);
\d+ pt2 \d+ fd_pt2
\d+ pt2_1 \d+ fd_pt2_1
-- cannot add column to a partition -- cannot add column to a partition
ALTER TABLE pt2_1 ADD c4 char; ALTER TABLE fd_pt2_1 ADD c4 char;
-- ok to have a partition's own constraints though -- ok to have a partition's own constraints though
ALTER TABLE pt2_1 ALTER c3 SET NOT NULL; ALTER TABLE fd_pt2_1 ALTER c3 SET NOT NULL;
ALTER TABLE pt2_1 ADD CONSTRAINT p21chk CHECK (c2 <> ''); ALTER TABLE fd_pt2_1 ADD CONSTRAINT p21chk CHECK (c2 <> '');
\d+ pt2 \d+ fd_pt2
\d+ pt2_1 \d+ fd_pt2_1
-- cannot drop inherited NOT NULL constraint from a partition -- cannot drop inherited NOT NULL constraint from a partition
ALTER TABLE pt2_1 ALTER c1 DROP NOT NULL; ALTER TABLE fd_pt2_1 ALTER c1 DROP NOT NULL;
-- partition must have parent's constraints -- partition must have parent's constraints
ALTER TABLE pt2 DETACH PARTITION pt2_1; ALTER TABLE fd_pt2 DETACH PARTITION fd_pt2_1;
ALTER TABLE pt2 ALTER c2 SET NOT NULL; ALTER TABLE fd_pt2 ALTER c2 SET NOT NULL;
\d+ pt2 \d+ fd_pt2
\d+ pt2_1 \d+ fd_pt2_1
ALTER TABLE pt2 ATTACH PARTITION pt2_1 FOR VALUES IN (1); -- ERROR ALTER TABLE fd_pt2 ATTACH PARTITION fd_pt2_1 FOR VALUES IN (1); -- ERROR
ALTER FOREIGN TABLE pt2_1 ALTER c2 SET NOT NULL; ALTER FOREIGN TABLE fd_pt2_1 ALTER c2 SET NOT NULL;
ALTER TABLE pt2 ATTACH PARTITION pt2_1 FOR VALUES IN (1); ALTER TABLE fd_pt2 ATTACH PARTITION fd_pt2_1 FOR VALUES IN (1);
ALTER TABLE pt2 DETACH PARTITION pt2_1; ALTER TABLE fd_pt2 DETACH PARTITION fd_pt2_1;
ALTER TABLE pt2 ADD CONSTRAINT pt2chk1 CHECK (c1 > 0); ALTER TABLE fd_pt2 ADD CONSTRAINT fd_pt2chk1 CHECK (c1 > 0);
\d+ pt2 \d+ fd_pt2
\d+ pt2_1 \d+ fd_pt2_1
ALTER TABLE pt2 ATTACH PARTITION pt2_1 FOR VALUES IN (1); -- ERROR ALTER TABLE fd_pt2 ATTACH PARTITION fd_pt2_1 FOR VALUES IN (1); -- ERROR
ALTER FOREIGN TABLE pt2_1 ADD CONSTRAINT pt2chk1 CHECK (c1 > 0); ALTER FOREIGN TABLE fd_pt2_1 ADD CONSTRAINT fd_pt2chk1 CHECK (c1 > 0);
ALTER TABLE pt2 ATTACH PARTITION pt2_1 FOR VALUES IN (1); ALTER TABLE fd_pt2 ATTACH PARTITION fd_pt2_1 FOR VALUES IN (1);
-- TRUNCATE doesn't work on foreign tables, either directly or recursively -- TRUNCATE doesn't work on foreign tables, either directly or recursively
TRUNCATE pt2_1; -- ERROR TRUNCATE fd_pt2_1; -- ERROR
TRUNCATE pt2; -- ERROR TRUNCATE fd_pt2; -- ERROR
DROP FOREIGN TABLE pt2_1; DROP FOREIGN TABLE fd_pt2_1;
DROP TABLE pt2; DROP TABLE fd_pt2;
-- Cleanup -- Cleanup
DROP SCHEMA foreign_schema CASCADE; DROP SCHEMA foreign_schema CASCADE;
......
This diff is collapsed.
This diff is collapsed.
...@@ -159,21 +159,21 @@ select cachebug(); ...@@ -159,21 +159,21 @@ select cachebug();
-- Check that addition or removal of any partition is correctly dealt with by -- Check that addition or removal of any partition is correctly dealt with by
-- default partition table when it is being used in prepared statement. -- default partition table when it is being used in prepared statement.
create table list_parted (a int) partition by list(a); create table pc_list_parted (a int) partition by list(a);
create table list_part_null partition of list_parted for values in (null); create table pc_list_part_null partition of pc_list_parted for values in (null);
create table list_part_1 partition of list_parted for values in (1); create table pc_list_part_1 partition of pc_list_parted for values in (1);
create table list_part_def partition of list_parted default; create table pc_list_part_def partition of pc_list_parted default;
prepare pstmt_def_insert (int) as insert into list_part_def values($1); prepare pstmt_def_insert (int) as insert into pc_list_part_def values($1);
-- should fail -- should fail
execute pstmt_def_insert(null); execute pstmt_def_insert(null);
execute pstmt_def_insert(1); execute pstmt_def_insert(1);
create table list_part_2 partition of list_parted for values in (2); create table pc_list_part_2 partition of pc_list_parted for values in (2);
execute pstmt_def_insert(2); execute pstmt_def_insert(2);
alter table list_parted detach partition list_part_null; alter table pc_list_parted detach partition pc_list_part_null;
-- should be ok -- should be ok
execute pstmt_def_insert(null); execute pstmt_def_insert(null);
drop table list_part_1; drop table pc_list_part_1;
-- should be ok -- should be ok
execute pstmt_def_insert(1); execute pstmt_def_insert(1);
drop table list_parted, list_part_null; drop table pc_list_parted, pc_list_part_null;
deallocate pstmt_def_insert; deallocate pstmt_def_insert;
This diff is collapsed.
...@@ -734,18 +734,18 @@ $$ language sql; ...@@ -734,18 +734,18 @@ $$ language sql;
drop function dfunc(varchar, numeric); drop function dfunc(varchar, numeric);
--fail, named parameters are not unique --fail, named parameters are not unique
create function testfoo(a int, a int) returns int as $$ select 1;$$ language sql; create function testpolym(a int, a int) returns int as $$ select 1;$$ language sql;
create function testfoo(int, out a int, out a int) returns int as $$ select 1;$$ language sql; create function testpolym(int, out a int, out a int) returns int as $$ select 1;$$ language sql;
create function testfoo(out a int, inout a int) returns int as $$ select 1;$$ language sql; create function testpolym(out a int, inout a int) returns int as $$ select 1;$$ language sql;
create function testfoo(a int, inout a int) returns int as $$ select 1;$$ language sql; create function testpolym(a int, inout a int) returns int as $$ select 1;$$ language sql;
-- valid -- valid
create function testfoo(a int, out a int) returns int as $$ select $1;$$ language sql; create function testpolym(a int, out a int) returns int as $$ select $1;$$ language sql;
select testfoo(37); select testpolym(37);
drop function testfoo(int); drop function testpolym(int);
create function testfoo(a int) returns table(a int) as $$ select $1;$$ language sql; create function testpolym(a int) returns table(a int) as $$ select $1;$$ language sql;
select * from testfoo(37); select * from testpolym(37);
drop function testfoo(int); drop function testpolym(int);
-- test polymorphic params and defaults -- test polymorphic params and defaults
create function dfunc(a anyelement, b anyelement = null, flag bool = true) create function dfunc(a anyelement, b anyelement = null, flag bool = true)
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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