From: Robert Haas Date: Wed, 22 Jun 2011 02:57:08 +0000 (-0400) Subject: Add some regression tests for serial pseudotypes. X-Git-Tag: REL9_2_BETA1~1518 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=431ab0e82819b31fcd1e33ecb52c2cd3b4b41da7;p=postgresql Add some regression tests for serial pseudotypes. Josh Kupershmidt --- diff --git a/src/test/regress/expected/sequence.out b/src/test/regress/expected/sequence.out index 13e1565272..968fcce8ac 100644 --- a/src/test/regress/expected/sequence.out +++ b/src/test/regress/expected/sequence.out @@ -16,6 +16,84 @@ SELECT * FROM serialTest; force | 100 (3 rows) +-- test smallserial / bigserial +CREATE TABLE serialTest2 (f1 text, f2 serial, f3 smallserial, f4 serial2, + f5 bigserial, f6 serial8); +NOTICE: CREATE TABLE will create implicit sequence "serialtest2_f2_seq" for serial column "serialtest2.f2" +NOTICE: CREATE TABLE will create implicit sequence "serialtest2_f3_seq" for serial column "serialtest2.f3" +NOTICE: CREATE TABLE will create implicit sequence "serialtest2_f4_seq" for serial column "serialtest2.f4" +NOTICE: CREATE TABLE will create implicit sequence "serialtest2_f5_seq" for serial column "serialtest2.f5" +NOTICE: CREATE TABLE will create implicit sequence "serialtest2_f6_seq" for serial column "serialtest2.f6" +INSERT INTO serialTest2 (f1) + VALUES ('test_defaults'); +INSERT INTO serialTest2 (f1, f2, f3, f4, f5, f6) + VALUES ('test_max_vals', 2147483647, 32767, 32767, 9223372036854775807, + 9223372036854775807), + ('test_min_vals', -2147483648, -32768, -32768, -9223372036854775808, + -9223372036854775808); +-- All these INSERTs should fail: +INSERT INTO serialTest2 (f1, f3) + VALUES ('bogus', -32769); +ERROR: smallint out of range +INSERT INTO serialTest2 (f1, f4) + VALUES ('bogus', -32769); +ERROR: smallint out of range +INSERT INTO serialTest2 (f1, f3) + VALUES ('bogus', 32768); +ERROR: smallint out of range +INSERT INTO serialTest2 (f1, f4) + VALUES ('bogus', 32768); +ERROR: smallint out of range +INSERT INTO serialTest2 (f1, f5) + VALUES ('bogus', -9223372036854775809); +ERROR: bigint out of range +INSERT INTO serialTest2 (f1, f6) + VALUES ('bogus', -9223372036854775809); +ERROR: bigint out of range +INSERT INTO serialTest2 (f1, f5) + VALUES ('bogus', 9223372036854775808); +ERROR: bigint out of range +INSERT INTO serialTest2 (f1, f6) + VALUES ('bogus', 9223372036854775808); +ERROR: bigint out of range +SELECT * FROM serialTest2 ORDER BY f2 ASC; + f1 | f2 | f3 | f4 | f5 | f6 +---------------+-------------+--------+--------+----------------------+---------------------- + test_min_vals | -2147483648 | -32768 | -32768 | -9223372036854775808 | -9223372036854775808 + test_defaults | 1 | 1 | 1 | 1 | 1 + test_max_vals | 2147483647 | 32767 | 32767 | 9223372036854775807 | 9223372036854775807 +(3 rows) + +SELECT nextval('serialTest2_f2_seq'); + nextval +--------- + 2 +(1 row) + +SELECT nextval('serialTest2_f3_seq'); + nextval +--------- + 2 +(1 row) + +SELECT nextval('serialTest2_f4_seq'); + nextval +--------- + 2 +(1 row) + +SELECT nextval('serialTest2_f5_seq'); + nextval +--------- + 2 +(1 row) + +SELECT nextval('serialTest2_f6_seq'); + nextval +--------- + 2 +(1 row) + -- basic sequence operations using both text and oid references CREATE SEQUENCE sequence_test; SELECT nextval('sequence_test'::text); @@ -221,11 +299,19 @@ SELECT nextval('sequence_test2'); (1 row) -- Information schema -SELECT * FROM information_schema.sequences WHERE sequence_name IN ('sequence_test2'); - sequence_catalog | sequence_schema | sequence_name | data_type | numeric_precision | numeric_precision_radix | numeric_scale | start_value | minimum_value | maximum_value | increment | cycle_option -------------------+-----------------+----------------+-----------+-------------------+-------------------------+---------------+-------------+---------------+---------------+-----------+-------------- - regression | public | sequence_test2 | bigint | 64 | 2 | 0 | 32 | 5 | 36 | 4 | YES -(1 row) +SELECT * FROM information_schema.sequences WHERE sequence_name IN + ('sequence_test2', 'serialtest2_f2_seq', 'serialtest2_f3_seq', + 'serialtest2_f4_seq', 'serialtest2_f5_seq', 'serialtest2_f6_seq') + ORDER BY sequence_name ASC; + sequence_catalog | sequence_schema | sequence_name | data_type | numeric_precision | numeric_precision_radix | numeric_scale | start_value | minimum_value | maximum_value | increment | cycle_option +------------------+-----------------+--------------------+-----------+-------------------+-------------------------+---------------+-------------+---------------+---------------------+-----------+-------------- + regression | public | sequence_test2 | bigint | 64 | 2 | 0 | 32 | 5 | 36 | 4 | YES + regression | public | serialtest2_f2_seq | bigint | 64 | 2 | 0 | 1 | 1 | 9223372036854775807 | 1 | NO + regression | public | serialtest2_f3_seq | bigint | 64 | 2 | 0 | 1 | 1 | 9223372036854775807 | 1 | NO + regression | public | serialtest2_f4_seq | bigint | 64 | 2 | 0 | 1 | 1 | 9223372036854775807 | 1 | NO + regression | public | serialtest2_f5_seq | bigint | 64 | 2 | 0 | 1 | 1 | 9223372036854775807 | 1 | NO + regression | public | serialtest2_f6_seq | bigint | 64 | 2 | 0 | 1 | 1 | 9223372036854775807 | 1 | NO +(6 rows) -- Test comments COMMENT ON SEQUENCE asdf IS 'won''t work'; @@ -289,5 +375,17 @@ REVOKE ALL ON seq3 FROM seq_user; SELECT lastval(); ERROR: permission denied for sequence seq3 ROLLBACK; +-- Sequences should get wiped out as well: +DROP TABLE serialTest, serialTest2; +-- Make sure sequences are gone: +SELECT * FROM information_schema.sequences WHERE sequence_name IN + ('sequence_test2', 'serialtest2_f2_seq', 'serialtest2_f3_seq', + 'serialtest2_f4_seq', 'serialtest2_f5_seq', 'serialtest2_f6_seq') + ORDER BY sequence_name ASC; + sequence_catalog | sequence_schema | sequence_name | data_type | numeric_precision | numeric_precision_radix | numeric_scale | start_value | minimum_value | maximum_value | increment | cycle_option +------------------+-----------------+----------------+-----------+-------------------+-------------------------+---------------+-------------+---------------+---------------+-----------+-------------- + regression | public | sequence_test2 | bigint | 64 | 2 | 0 | 32 | 5 | 36 | 4 | YES +(1 row) + DROP USER seq_user; DROP SEQUENCE seq; diff --git a/src/test/regress/sql/sequence.sql b/src/test/regress/sql/sequence.sql index 29ea69123a..97ffb60385 100644 --- a/src/test/regress/sql/sequence.sql +++ b/src/test/regress/sql/sequence.sql @@ -11,6 +11,52 @@ INSERT INTO serialTest VALUES ('wrong', NULL); SELECT * FROM serialTest; +-- test smallserial / bigserial +CREATE TABLE serialTest2 (f1 text, f2 serial, f3 smallserial, f4 serial2, + f5 bigserial, f6 serial8); + +INSERT INTO serialTest2 (f1) + VALUES ('test_defaults'); + +INSERT INTO serialTest2 (f1, f2, f3, f4, f5, f6) + VALUES ('test_max_vals', 2147483647, 32767, 32767, 9223372036854775807, + 9223372036854775807), + ('test_min_vals', -2147483648, -32768, -32768, -9223372036854775808, + -9223372036854775808); + +-- All these INSERTs should fail: +INSERT INTO serialTest2 (f1, f3) + VALUES ('bogus', -32769); + +INSERT INTO serialTest2 (f1, f4) + VALUES ('bogus', -32769); + +INSERT INTO serialTest2 (f1, f3) + VALUES ('bogus', 32768); + +INSERT INTO serialTest2 (f1, f4) + VALUES ('bogus', 32768); + +INSERT INTO serialTest2 (f1, f5) + VALUES ('bogus', -9223372036854775809); + +INSERT INTO serialTest2 (f1, f6) + VALUES ('bogus', -9223372036854775809); + +INSERT INTO serialTest2 (f1, f5) + VALUES ('bogus', 9223372036854775808); + +INSERT INTO serialTest2 (f1, f6) + VALUES ('bogus', 9223372036854775808); + +SELECT * FROM serialTest2 ORDER BY f2 ASC; + +SELECT nextval('serialTest2_f2_seq'); +SELECT nextval('serialTest2_f3_seq'); +SELECT nextval('serialTest2_f4_seq'); +SELECT nextval('serialTest2_f5_seq'); +SELECT nextval('serialTest2_f6_seq'); + -- basic sequence operations using both text and oid references CREATE SEQUENCE sequence_test; @@ -86,7 +132,10 @@ SELECT nextval('sequence_test2'); SELECT nextval('sequence_test2'); -- Information schema -SELECT * FROM information_schema.sequences WHERE sequence_name IN ('sequence_test2'); +SELECT * FROM information_schema.sequences WHERE sequence_name IN + ('sequence_test2', 'serialtest2_f2_seq', 'serialtest2_f3_seq', + 'serialtest2_f4_seq', 'serialtest2_f5_seq', 'serialtest2_f6_seq') + ORDER BY sequence_name ASC; -- Test comments COMMENT ON SEQUENCE asdf IS 'won''t work'; @@ -118,5 +167,14 @@ REVOKE ALL ON seq3 FROM seq_user; SELECT lastval(); ROLLBACK; +-- Sequences should get wiped out as well: +DROP TABLE serialTest, serialTest2; + +-- Make sure sequences are gone: +SELECT * FROM information_schema.sequences WHERE sequence_name IN + ('sequence_test2', 'serialtest2_f2_seq', 'serialtest2_f3_seq', + 'serialtest2_f4_seq', 'serialtest2_f5_seq', 'serialtest2_f6_seq') + ORDER BY sequence_name ASC; + DROP USER seq_user; DROP SEQUENCE seq;