確認用SQL
-- 確認
SELECT * FROM test_seq;
-- セット
SELECT setval('test_seq',1,true);
-- 採番
select nextval('test_seq');
-- セット
SELECT setval('test_seq',1,false);
-- 採番
select nextval('test_seq');
参考
確認用SQLPostgres: Get nextval in sequence without actually incrementing sequence?
-- 確認
SELECT * FROM test_seq;
-- セット
SELECT setval('test_seq',1,true);
-- 採番
select nextval('test_seq');
-- セット
SELECT setval('test_seq',1,false);
-- 採番
select nextval('test_seq');
Based on previous answers I realised that it fails for the first value added: The query returns 2 instead on 1 when there are no values added. Here is my solution:
SELECT (CASE WHEN is_called THEN last_value + i.inc ELSE last_value END ) AS nextvalue FROM myserial, (SELECT seqincrement AS inc FROM pg_sequence WHERE seqrelid = 'myserial'::regclass::oid) AS i;