@@ -32,19 +32,35 @@ DROP TABLE sequence_test_table;
3232CREATE SEQUENCE sequence_test5 AS integer;
3333CREATE SEQUENCE sequence_test6 AS smallint;
3434CREATE SEQUENCE sequence_test7 AS bigint;
35+ CREATE SEQUENCE sequence_test8 AS integer MAXVALUE 100000;
36+ CREATE SEQUENCE sequence_test9 AS integer INCREMENT BY -1;
37+ CREATE SEQUENCE sequence_test10 AS integer MINVALUE -100000 START 1;
38+ CREATE SEQUENCE sequence_test11 AS smallint;
39+ CREATE SEQUENCE sequence_test12 AS smallint INCREMENT -1;
40+ CREATE SEQUENCE sequence_test13 AS smallint MINVALUE -32768;
41+ CREATE SEQUENCE sequence_test14 AS smallint MAXVALUE 32767 INCREMENT -1;
3542CREATE SEQUENCE sequence_testx AS text;
3643ERROR: sequence type must be smallint, integer, or bigint
3744CREATE SEQUENCE sequence_testx AS nosuchtype;
3845ERROR: type "nosuchtype" does not exist
3946LINE 1: CREATE SEQUENCE sequence_testx AS nosuchtype;
4047 ^
41- ALTER SEQUENCE sequence_test5 AS smallint; -- fails
42- ERROR: MAXVALUE (2147483647) is out of range for sequence data type smallint
43- ALTER SEQUENCE sequence_test5 AS smallint NO MINVALUE NO MAXVALUE;
4448CREATE SEQUENCE sequence_testx AS smallint MAXVALUE 100000;
4549ERROR: MAXVALUE (100000) is out of range for sequence data type smallint
4650CREATE SEQUENCE sequence_testx AS smallint MINVALUE -100000;
4751ERROR: MINVALUE (-100000) is out of range for sequence data type smallint
52+ ALTER SEQUENCE sequence_test5 AS smallint; -- success, max will be adjusted
53+ ALTER SEQUENCE sequence_test8 AS smallint; -- fail, max has to be adjusted
54+ ERROR: MAXVALUE (100000) is out of range for sequence data type smallint
55+ ALTER SEQUENCE sequence_test8 AS smallint MAXVALUE 20000; -- ok now
56+ ALTER SEQUENCE sequence_test9 AS smallint; -- success, min will be adjusted
57+ ALTER SEQUENCE sequence_test10 AS smallint; -- fail, min has to be adjusted
58+ ERROR: MINVALUE (-100000) is out of range for sequence data type smallint
59+ ALTER SEQUENCE sequence_test10 AS smallint MINVALUE -20000; -- ok now
60+ ALTER SEQUENCE sequence_test11 AS int; -- max will be adjusted
61+ ALTER SEQUENCE sequence_test12 AS int; -- min will be adjusted
62+ ALTER SEQUENCE sequence_test13 AS int; -- min and max will be adjusted
63+ ALTER SEQUENCE sequence_test14 AS int; -- min and max will be adjusted
4864---
4965--- test creation of SERIAL column
5066---
@@ -459,39 +475,53 @@ SELECT * FROM information_schema.sequences
459475 ORDER BY sequence_name ASC;
460476 sequence_catalog | sequence_schema | sequence_name | data_type | numeric_precision | numeric_precision_radix | numeric_scale | start_value | minimum_value | maximum_value | increment | cycle_option
461477------------------+-----------------+--------------------+-----------+-------------------+-------------------------+---------------+-------------+----------------------+---------------------+-----------+--------------
478+ regression | public | sequence_test10 | smallint | 16 | 2 | 0 | 1 | -20000 | 32767 | 1 | NO
479+ regression | public | sequence_test11 | integer | 32 | 2 | 0 | 1 | 1 | 2147483647 | 1 | NO
480+ regression | public | sequence_test12 | integer | 32 | 2 | 0 | -1 | -2147483648 | -1 | -1 | NO
481+ regression | public | sequence_test13 | integer | 32 | 2 | 0 | -32768 | -2147483648 | 2147483647 | 1 | NO
482+ regression | public | sequence_test14 | integer | 32 | 2 | 0 | 32767 | -2147483648 | 2147483647 | -1 | NO
462483 regression | public | sequence_test2 | bigint | 64 | 2 | 0 | 32 | 5 | 36 | 4 | YES
463484 regression | public | sequence_test3 | bigint | 64 | 2 | 0 | 1 | 1 | 9223372036854775807 | 1 | NO
464485 regression | public | sequence_test4 | bigint | 64 | 2 | 0 | -1 | -9223372036854775808 | -1 | -1 | NO
465486 regression | public | sequence_test5 | smallint | 16 | 2 | 0 | 1 | 1 | 32767 | 1 | NO
466487 regression | public | sequence_test6 | smallint | 16 | 2 | 0 | 1 | 1 | 32767 | 1 | NO
467488 regression | public | sequence_test7 | bigint | 64 | 2 | 0 | 1 | 1 | 9223372036854775807 | 1 | NO
489+ regression | public | sequence_test8 | smallint | 16 | 2 | 0 | 1 | 1 | 20000 | 1 | NO
490+ regression | public | sequence_test9 | smallint | 16 | 2 | 0 | -1 | -32768 | -1 | -1 | NO
468491 regression | public | serialtest1_f2_foo | integer | 32 | 2 | 0 | 1 | 1 | 2147483647 | 1 | NO
469492 regression | public | serialtest2_f2_seq | integer | 32 | 2 | 0 | 1 | 1 | 2147483647 | 1 | NO
470493 regression | public | serialtest2_f3_seq | smallint | 16 | 2 | 0 | 1 | 1 | 32767 | 1 | NO
471494 regression | public | serialtest2_f4_seq | smallint | 16 | 2 | 0 | 1 | 1 | 32767 | 1 | NO
472495 regression | public | serialtest2_f5_seq | bigint | 64 | 2 | 0 | 1 | 1 | 9223372036854775807 | 1 | NO
473496 regression | public | serialtest2_f6_seq | bigint | 64 | 2 | 0 | 1 | 1 | 9223372036854775807 | 1 | NO
474- (12 rows)
497+ (19 rows)
475498
476499SELECT schemaname, sequencename, start_value, min_value, max_value, increment_by, cycle, cache_size, last_value
477500FROM pg_sequences
478501WHERE sequencename ~ ANY(ARRAY['sequence_test', 'serialtest'])
479502 ORDER BY sequencename ASC;
480503 schemaname | sequencename | start_value | min_value | max_value | increment_by | cycle | cache_size | last_value
481504------------+--------------------+-------------+----------------------+---------------------+--------------+-------+------------+------------
505+ public | sequence_test10 | 1 | -20000 | 32767 | 1 | f | 1 |
506+ public | sequence_test11 | 1 | 1 | 2147483647 | 1 | f | 1 |
507+ public | sequence_test12 | -1 | -2147483648 | -1 | -1 | f | 1 |
508+ public | sequence_test13 | -32768 | -2147483648 | 2147483647 | 1 | f | 1 |
509+ public | sequence_test14 | 32767 | -2147483648 | 2147483647 | -1 | f | 1 |
482510 public | sequence_test2 | 32 | 5 | 36 | 4 | t | 1 | 5
483511 public | sequence_test3 | 1 | 1 | 9223372036854775807 | 1 | f | 1 |
484512 public | sequence_test4 | -1 | -9223372036854775808 | -1 | -1 | f | 1 | -1
485513 public | sequence_test5 | 1 | 1 | 32767 | 1 | f | 1 |
486514 public | sequence_test6 | 1 | 1 | 32767 | 1 | f | 1 |
487515 public | sequence_test7 | 1 | 1 | 9223372036854775807 | 1 | f | 1 |
516+ public | sequence_test8 | 1 | 1 | 20000 | 1 | f | 1 |
517+ public | sequence_test9 | -1 | -32768 | -1 | -1 | f | 1 |
488518 public | serialtest1_f2_foo | 1 | 1 | 2147483647 | 1 | f | 1 | 3
489519 public | serialtest2_f2_seq | 1 | 1 | 2147483647 | 1 | f | 1 | 2
490520 public | serialtest2_f3_seq | 1 | 1 | 32767 | 1 | f | 1 | 2
491521 public | serialtest2_f4_seq | 1 | 1 | 32767 | 1 | f | 1 | 2
492522 public | serialtest2_f5_seq | 1 | 1 | 9223372036854775807 | 1 | f | 1 | 2
493523 public | serialtest2_f6_seq | 1 | 1 | 9223372036854775807 | 1 | f | 1 | 2
494- (12 rows)
524+ (19 rows)
495525
496526SELECT * FROM pg_sequence_parameters('sequence_test4'::regclass);
497527 start_value | minimum_value | maximum_value | increment | cycle_option | cache_size | data_type
0 commit comments