1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-12 02:37:31 +03:00

Todo items:

Add ALTER SEQUENCE to modify min/max/increment/cache/cycle values

Also updated create sequence docs to mention NO MINVALUE, & NO MAXVALUE.

New Files:
doc/src/sgml/ref/alter_sequence.sgml
src/test/regress/expected/sequence.out
src/test/regress/sql/sequence.sql


ALTER SEQUENCE is NOT transactional.  It behaves similarly to setval().
It matches the proposed SQL200N spec, as well as Oracle in most ways --
Oracle lacks RESTART WITH for some strange reason.

--
Rod Taylor <rbt@rbt.ca>
This commit is contained in:
Bruce Momjian
2003-03-20 07:02:11 +00:00
parent 46bce088c1
commit 5f65225fa3
22 changed files with 631 additions and 125 deletions

View File

@@ -286,16 +286,6 @@ SELECT unique1 FROM tenk1 WHERE unique1 < 5;
(5 rows)
DROP VIEW tmp_view_new;
-- renaming sequences
CREATE SEQUENCE foo_seq;
ALTER TABLE foo_seq RENAME TO foo_seq_new;
SELECT * FROM foo_seq_new;
sequence_name | last_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called
---------------+------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------
foo_seq | 1 | 1 | 9223372036854775807 | 1 | 1 | 1 | f | f
(1 row)
DROP SEQUENCE foo_seq_new;
-- toast-like relation name
alter table stud_emp rename to pg_toast_stud_emp;
alter table pg_toast_stud_emp rename to stud_emp;

View File

@@ -132,31 +132,3 @@ INSERT INTO iportaltest (i, d, p)
VALUES (1, 3.567, '(3.0,1.0),(4.0,2.0)'::polygon);
INSERT INTO iportaltest (i, d, p)
VALUES (2, 89.05, '(4.0,2.0),(3.0,1.0)'::polygon);
---
--- test creation of SERIAL column
---
CREATE TABLE serialTest (f1 text, f2 serial);
NOTICE: CREATE TABLE will create implicit sequence 'serialtest_f2_seq' for SERIAL column 'serialtest.f2'
INSERT INTO serialTest VALUES ('foo');
INSERT INTO serialTest VALUES ('bar');
INSERT INTO serialTest VALUES ('force', 100);
INSERT INTO serialTest VALUES ('wrong', NULL);
ERROR: ExecInsert: Fail to add null value in not null attribute f2
SELECT * FROM serialTest;
f1 | f2
-------+-----
foo | 1
bar | 2
force | 100
(3 rows)
CREATE SEQUENCE sequence_test;
BEGIN;
SELECT nextval('sequence_test');
nextval
---------
1
(1 row)
DROP SEQUENCE sequence_test;
END;

View File

@@ -0,0 +1,73 @@
---
--- test creation of SERIAL column
---
CREATE TABLE serialTest (f1 text, f2 serial);
NOTICE: CREATE TABLE will create implicit sequence 'serialtest_f2_seq' for SERIAL column 'serialtest.f2'
INSERT INTO serialTest VALUES ('foo');
INSERT INTO serialTest VALUES ('bar');
INSERT INTO serialTest VALUES ('force', 100);
INSERT INTO serialTest VALUES ('wrong', NULL);
ERROR: ExecInsert: Fail to add null value in not null attribute f2
SELECT * FROM serialTest;
f1 | f2
-------+-----
foo | 1
bar | 2
force | 100
(3 rows)
CREATE SEQUENCE sequence_test;
BEGIN;
SELECT nextval('sequence_test');
nextval
---------
1
(1 row)
DROP SEQUENCE sequence_test;
END;
-- renaming sequences
CREATE SEQUENCE foo_seq;
ALTER TABLE foo_seq RENAME TO foo_seq_new;
SELECT * FROM foo_seq_new;
sequence_name | last_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called
---------------+------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------
foo_seq | 1 | 1 | 9223372036854775807 | 1 | 1 | 1 | f | f
(1 row)
DROP SEQUENCE foo_seq_new;
--
-- Alter sequence
--
CREATE SEQUENCE sequence_test2 START WITH 32;
SELECT nextval('sequence_test2');
nextval
---------
32
(1 row)
ALTER SEQUENCE sequence_test2 RESTART WITH 16
INCREMENT BY 4 MAXVALUE 22 MINVALUE 5 CYCLE;
SELECT nextval('sequence_test2');
nextval
---------
16
(1 row)
SELECT nextval('sequence_test2');
nextval
---------
20
(1 row)
SELECT nextval('sequence_test2');
nextval
---------
5
(1 row)

View File

@@ -74,4 +74,4 @@ test: select_views portals_p2 rules foreign_key cluster
# The sixth group of parallel test
# ----------
# "plpgsql" cannot run concurrently with "rules"
test: limit plpgsql copy2 temp domain rangefuncs prepare without_oid conversion truncate alter_table
test: limit plpgsql copy2 temp domain rangefuncs prepare without_oid conversion truncate alter_table sequence

View File

@@ -1,4 +1,4 @@
# $Header: /cvsroot/pgsql/src/test/regress/serial_schedule,v 1.18 2002/09/02 05:55:43 momjian Exp $
# $Header: /cvsroot/pgsql/src/test/regress/serial_schedule,v 1.19 2003/03/20 07:02:11 momjian Exp $
# This should probably be in an order similar to parallel_schedule.
test: boolean
test: char
@@ -90,3 +90,4 @@ test: without_oid
test: conversion
test: truncate
test: alter_table
test: sequence

View File

@@ -173,11 +173,6 @@ ALTER TABLE tmp_view RENAME TO tmp_view_new;
-- 5 values, sorted
SELECT unique1 FROM tenk1 WHERE unique1 < 5;
DROP VIEW tmp_view_new;
-- renaming sequences
CREATE SEQUENCE foo_seq;
ALTER TABLE foo_seq RENAME TO foo_seq_new;
SELECT * FROM foo_seq_new;
DROP SEQUENCE foo_seq_new;
-- toast-like relation name
alter table stud_emp rename to pg_toast_stud_emp;
alter table pg_toast_stud_emp rename to stud_emp;

View File

@@ -203,24 +203,3 @@ INSERT INTO iportaltest (i, d, p)
INSERT INTO iportaltest (i, d, p)
VALUES (2, 89.05, '(4.0,2.0),(3.0,1.0)'::polygon);
---
--- test creation of SERIAL column
---
CREATE TABLE serialTest (f1 text, f2 serial);
INSERT INTO serialTest VALUES ('foo');
INSERT INTO serialTest VALUES ('bar');
INSERT INTO serialTest VALUES ('force', 100);
INSERT INTO serialTest VALUES ('wrong', NULL);
SELECT * FROM serialTest;
CREATE SEQUENCE sequence_test;
BEGIN;
SELECT nextval('sequence_test');
DROP SEQUENCE sequence_test;
END;

View File

@@ -0,0 +1,39 @@
---
--- test creation of SERIAL column
---
CREATE TABLE serialTest (f1 text, f2 serial);
INSERT INTO serialTest VALUES ('foo');
INSERT INTO serialTest VALUES ('bar');
INSERT INTO serialTest VALUES ('force', 100);
INSERT INTO serialTest VALUES ('wrong', NULL);
SELECT * FROM serialTest;
CREATE SEQUENCE sequence_test;
BEGIN;
SELECT nextval('sequence_test');
DROP SEQUENCE sequence_test;
END;
-- renaming sequences
CREATE SEQUENCE foo_seq;
ALTER TABLE foo_seq RENAME TO foo_seq_new;
SELECT * FROM foo_seq_new;
DROP SEQUENCE foo_seq_new;
--
-- Alter sequence
--
CREATE SEQUENCE sequence_test2 START WITH 32;
SELECT nextval('sequence_test2');
ALTER SEQUENCE sequence_test2 RESTART WITH 16
INCREMENT BY 4 MAXVALUE 22 MINVALUE 5 CYCLE;
SELECT nextval('sequence_test2');
SELECT nextval('sequence_test2');
SELECT nextval('sequence_test2');