Supplements and suggestions and about postgresql sequence setval function in the documents

From: "yanliang lei" <msdnchina(at)163(dot)com>
To: "pgsql-docs(at)lists(dot)postgresql(dot)org" <pgsql-docs(at)lists(dot)postgresql(dot)org>
Subject: Supplements and suggestions and about postgresql sequence setval function in the documents
Date: 2024-08-21 12:23:40
Message-ID: 33f1f47d.9f8f.19174e48943.Coremail.msdnchina@163.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

in the following example;
select setval('seq_test',111);
---this setval('seq_test',111) : update the current schema's seq_test last_value =111

select setval('schemalei.seq_test',222);
---this setval('seq_test',111) : update the schemalei schema's seq_test last_value =222

but in the setval document(https://www.postgresql.org/docs/current/functions-sequence.html), there is no description about it.

[pg164(at)localhost bin]$ ./psql -d postgres
psql (16.4)
Type "help" for help.

postgres=# \d
Did not find any relations.
postgres=#
postgres=#
postgres=# create schema schemalei;
CREATE SCHEMA
postgres=# create sequence public.seq_test ;
CREATE SEQUENCE
postgres=# create sequence schemalei.seq_test ;
CREATE SEQUENCE
postgres=# show search_path;
search_path
-----------------
"$user", public
(1 row)

postgres=# \dus
List of roles
Role name | Attributes
-----------+------------------------------------------------------------
pg164 | Superuser, Create role, Create DB, Replication, Bypass RLS

postgres=# select * from pg_sequences;
schemaname | sequencename | sequenceowner | data_type | start_value | min_value | max_value | increment_by | cycle | cache_size | last_value
------------+--------------+---------------+-----------+-------------+-----------+---------------------+--------------+-------+------------+------------
public | seq_test | pg164 | bigint | 1 | 1 | 9223372036854775807 | 1 | f | 1 |
schemalei | seq_test | pg164 | bigint | 1 | 1 | 9223372036854775807 | 1 | f | 1 |
(2 rows)

postgres=# select setval('seq_test',111);
setval
--------
111
(1 row)

postgres=# select setval('schemalei.seq_test',222);
setval
--------
222
(1 row)

postgres=# select * from pg_sequences;
schemaname | sequencename | sequenceowner | data_type | start_value | min_value | max_value | increment_by | cycle | cache_size | last_value
------------+--------------+---------------+-----------+-------------+-----------+---------------------+--------------+-------+------------+------------
public | seq_test | pg164 | bigint | 1 | 1 | 9223372036854775807 | 1 | f | 1 | 111
schemalei | seq_test | pg164 | bigint | 1 | 1 | 9223372036854775807 | 1 | f | 1 | 222
(2 rows)

postgres=# select version();
version
-----------------------------------------------------------------------------
PostgreSQL 16.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 7.3.0, 64-bit
(1 row)

postgres=#

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message David G. Johnston 2024-08-21 13:01:35 Re: Supplements and suggestions and about postgresql sequence setval function in the documents
Previous Message Alvaro Herrera 2024-08-20 21:54:59 Re: nchar is undocumented