diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 82fba48d5f..3be2c5ef97 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -17623,7 +17623,12 @@ $.* ? (@ like_regex "^\\d+$") values beginning with 1. Other behaviors can be obtained by using appropriate parameters in the command. - + + + +nextval('myseq'); + + This function requires USAGE or UPDATE privilege on the sequence. @@ -17657,11 +17662,11 @@ $.* ? (@ like_regex "^\\d+$") Furthermore, the value reported by currval is not changed in this case. For example, -SELECT setval('myseq', 42); Next nextval will return 43 -SELECT setval('myseq', 42, true); Same as above -SELECT setval('myseq', 42, false); Next nextval will return 42 +SELECT setval('myseq', 42); -- The next nextval('myseq') will return 43 +SELECT setval('myseq', 42, true); -- Same as above +SELECT setval('myseq', 42, false); -- The next nextval('myseq') will return 42 - The result returned by setval is just the value of its + The result returned by setval is the value of its second argument. @@ -17686,6 +17691,9 @@ SELECT setval('myseq', 42, false); Next nextvalnextval since the current session did. + +currval('myseq'); + This function requires USAGE @@ -17707,9 +17715,8 @@ SELECT setval('myseq', 42, false); Next nextvalcurrval, except that instead of taking the sequence name as an argument it refers to whichever sequence nextval was most recently applied to - in the current session. It is an error to call - lastval if nextval - has not yet been called in the current session. + in the current session. (An error is reported if nextval has + never been called in this session.) This function requires USAGE @@ -17719,7 +17726,21 @@ SELECT setval('myseq', 42, false); Next nextval + Example + +CREATE SEQUENCE test_seq; + +SELECT nextval('test_seq'::regclass); -- 1 +SELECT currval('test_seq'); -- 1 +SELECT lastval(); -- 1 + +-- Using the DEFAULT value you can assign this SEQUENCE to be used when the field is not assigned a value +CREATE TABLE t1 (id bigint NOT NULL DEFAULT nextval('test_seq'), other_data text); -- links column/sequence + +INSERT INTO t1 (other_data) VALUES ('Some Data'); -- Assigns the next ID automatically + + To avoid blocking concurrent transactions that obtain numbers from