Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0172b4c

Browse files
committed
Add some regression tests for missing DDL patterns
The following commands gain increased coverage for some of the errors they can trigger: - ALTER TABLE .. ALTER COLUMN - CREATE DOMAIN - CREATE TYPE (LIKE) This has come up while discussing the possibility to add more information about the location of the error in such queries, and it is useful on its own as there was no coverage until now for the patterns added in this commit. Author: Jian He, Kirill Reshke Reviewed-By: Álvaro Herrera, Michael Paquier Discussion: https://postgr.es/m/CALdSSPhqfvKbDwqJaY=yEePi_aq61GmMpW88i6ZH7CMG_2Z4Cg@mail.gmail.com
1 parent 430a595 commit 0172b4c

File tree

8 files changed

+59
-0
lines changed

8 files changed

+59
-0
lines changed

src/test/regress/expected/alter_table.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3413,6 +3413,13 @@ ALTER TABLE comment_test ALTER COLUMN id SET DATA TYPE int;
34133413
ALTER TABLE comment_test ALTER COLUMN id SET DATA TYPE text;
34143414
ALTER TABLE comment_test ALTER COLUMN positive_col SET DATA TYPE int;
34153415
ALTER TABLE comment_test ALTER COLUMN positive_col SET DATA TYPE bigint;
3416+
-- Some error cases.
3417+
ALTER TABLE comment_test ALTER COLUMN xmin SET DATA TYPE x;
3418+
ERROR: cannot alter system column "xmin"
3419+
ALTER TABLE comment_test ALTER COLUMN id SET DATA TYPE x;
3420+
ERROR: type "x" does not exist
3421+
ALTER TABLE comment_test ALTER COLUMN id SET DATA TYPE int COLLATE "C";
3422+
ERROR: collations are not supported by type integer
34163423
-- Check that the comments are intact.
34173424
SELECT col_description('comment_test'::regclass, 1) as comment;
34183425
comment

src/test/regress/expected/domain.out

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,33 @@ NOTICE: drop cascades to type dependenttypetest
1515
-- this should fail because already gone
1616
drop domain domaindroptest cascade;
1717
ERROR: type "domaindroptest" does not exist
18+
-- some error cases
19+
create domain d_fail as no_such_type;
20+
ERROR: type "no_such_type" does not exist
21+
create domain d_fail as int constraint cc REFERENCES this_table_not_exists(i);
22+
ERROR: foreign key constraints not possible for domains
23+
create domain d_fail as int4 not null no inherit;
24+
ERROR: not-null constraints for domains cannot be marked NO INHERIT
25+
create domain d_fail as int4 not null null;
26+
ERROR: conflicting NULL/NOT NULL constraints
27+
create domain d_fail as int4 not null default 3 default 3;
28+
ERROR: multiple default expressions
29+
create domain d_fail int4 DEFAULT 3 + 'h';
30+
ERROR: invalid input syntax for type integer: "h"
31+
create domain d_fail int4 collate "C";
32+
ERROR: collations are not supported by type integer
33+
create domain d_fail as anyelement;
34+
ERROR: "anyelement" is not a valid base type for a domain
35+
create domain d_fail as int4 unique;
36+
ERROR: unique constraints not possible for domains
37+
create domain d_fail as int4 PRIMARY key;
38+
ERROR: primary key constraints not possible for domains
39+
create domain d_fail as int4 constraint cc generated by default as identity;
40+
ERROR: specifying GENERATED not supported for domains
41+
create domain d_fail as int4 constraint cc check (values > 1) no inherit;
42+
ERROR: check constraints for domains cannot be marked NO INHERIT
43+
create domain d_fail as int4 constraint cc check (values > 1) deferrable;
44+
ERROR: specifying constraint deferrability not supported for domains
1845
-- Test domain input.
1946
-- Note: the point of checking both INSERT and COPY FROM is that INSERT
2047
-- exercises CoerceToDomain while COPY exercises domain_in.

src/test/regress/expected/float8.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,8 @@ create function xfloat8out(xfloat8) returns cstring immutable strict
10241024
NOTICE: argument type xfloat8 is only a shell
10251025
LINE 1: create function xfloat8out(xfloat8) returns cstring immutabl...
10261026
^
1027+
create type xfloat8 (input = xfloat8in, output = xfloat8out, like = no_such_type);
1028+
ERROR: type "no_such_type" does not exist
10271029
create type xfloat8 (input = xfloat8in, output = xfloat8out, like = float8);
10281030
create cast (xfloat8 as float8) without function;
10291031
create cast (float8 as xfloat8) without function;

src/test/regress/expected/identity.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ CREATE TABLE itest4 (a int, b text);
4343
ALTER TABLE itest4 ALTER COLUMN a ADD GENERATED ALWAYS AS IDENTITY; -- error, requires NOT NULL
4444
ERROR: column "a" of relation "itest4" must be declared NOT NULL before identity can be added
4545
ALTER TABLE itest4 ALTER COLUMN a SET NOT NULL;
46+
ALTER TABLE itest4 ALTER COLUMN c ADD GENERATED ALWAYS AS IDENTITY; -- error, column c does not exist
47+
ERROR: column "c" of relation "itest4" does not exist
4648
ALTER TABLE itest4 ALTER COLUMN a ADD GENERATED ALWAYS AS IDENTITY; -- ok
4749
ALTER TABLE itest4 ALTER COLUMN a DROP NOT NULL; -- error, disallowed
4850
ERROR: column "a" of relation "itest4" is an identity column

src/test/regress/sql/alter_table.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,11 @@ ALTER TABLE comment_test ALTER COLUMN id SET DATA TYPE text;
21452145
ALTER TABLE comment_test ALTER COLUMN positive_col SET DATA TYPE int;
21462146
ALTER TABLE comment_test ALTER COLUMN positive_col SET DATA TYPE bigint;
21472147

2148+
-- Some error cases.
2149+
ALTER TABLE comment_test ALTER COLUMN xmin SET DATA TYPE x;
2150+
ALTER TABLE comment_test ALTER COLUMN id SET DATA TYPE x;
2151+
ALTER TABLE comment_test ALTER COLUMN id SET DATA TYPE int COLLATE "C";
2152+
21482153
-- Check that the comments are intact.
21492154
SELECT col_description('comment_test'::regclass, 1) as comment;
21502155
SELECT indexrelid::regclass::text as index, obj_description(indexrelid, 'pg_class') as comment FROM pg_index where indrelid = 'comment_test'::regclass ORDER BY 1, 2;

src/test/regress/sql/domain.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ drop domain domaindroptest cascade;
1616
-- this should fail because already gone
1717
drop domain domaindroptest cascade;
1818

19+
-- some error cases
20+
create domain d_fail as no_such_type;
21+
create domain d_fail as int constraint cc REFERENCES this_table_not_exists(i);
22+
create domain d_fail as int4 not null no inherit;
23+
create domain d_fail as int4 not null null;
24+
create domain d_fail as int4 not null default 3 default 3;
25+
create domain d_fail int4 DEFAULT 3 + 'h';
26+
create domain d_fail int4 collate "C";
27+
create domain d_fail as anyelement;
28+
create domain d_fail as int4 unique;
29+
create domain d_fail as int4 PRIMARY key;
30+
create domain d_fail as int4 constraint cc generated by default as identity;
31+
create domain d_fail as int4 constraint cc check (values > 1) no inherit;
32+
create domain d_fail as int4 constraint cc check (values > 1) deferrable;
1933

2034
-- Test domain input.
2135

src/test/regress/sql/float8.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ create function xfloat8in(cstring) returns xfloat8 immutable strict
328328
language internal as 'int8in';
329329
create function xfloat8out(xfloat8) returns cstring immutable strict
330330
language internal as 'int8out';
331+
create type xfloat8 (input = xfloat8in, output = xfloat8out, like = no_such_type);
331332
create type xfloat8 (input = xfloat8in, output = xfloat8out, like = float8);
332333
create cast (xfloat8 as float8) without function;
333334
create cast (float8 as xfloat8) without function;

src/test/regress/sql/identity.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ SELECT pg_get_serial_sequence('itest1', 'a');
1919
CREATE TABLE itest4 (a int, b text);
2020
ALTER TABLE itest4 ALTER COLUMN a ADD GENERATED ALWAYS AS IDENTITY; -- error, requires NOT NULL
2121
ALTER TABLE itest4 ALTER COLUMN a SET NOT NULL;
22+
ALTER TABLE itest4 ALTER COLUMN c ADD GENERATED ALWAYS AS IDENTITY; -- error, column c does not exist
2223
ALTER TABLE itest4 ALTER COLUMN a ADD GENERATED ALWAYS AS IDENTITY; -- ok
2324
ALTER TABLE itest4 ALTER COLUMN a DROP NOT NULL; -- error, disallowed
2425
ALTER TABLE itest4 ALTER COLUMN a ADD GENERATED ALWAYS AS IDENTITY; -- error, already set

0 commit comments

Comments
 (0)