Quick example:

xof=# CREATE TABLE t1 (id SERIAL PRIMARY KEY);
CREATE TABLE
xof=# CREATE TABLE t2 (id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY);
CREATE TABLE
xof=# \d+
                                       List of relations
 Schema |   Name    |   Type   | Owner | Persistence | Access method |    Size  
  | Description 
--------+-----------+----------+-------+-------------+---------------+------------+-------------
 public | t1        | table    | xof   | permanent   | heap          | 0 bytes  
  | 
 public | t1_id_seq | sequence | xof   | permanent   |               | 8192 
bytes | 
 public | t2        | table    | xof   | permanent   | heap          | 0 bytes  
  | 
 public | t2_id_seq | sequence | xof   | permanent   |               | 8192 
bytes | 
(4 rows)

Swift:~ xof$ pg_dump -t 't1_id_seq' | fgrep 'setval'
SELECT pg_catalog.setval('public.t1_id_seq', 1, false);
Swift:~ xof$ pg_dump -t 't2_id_seq' | fgrep 'setval'
Swift:~ xof$ pg_dump -t 't2' | fgrep 'setval'
SELECT pg_catalog.setval('public.t2_id_seq', 1, false);
Swift:~ xof$ 

So, you can dump a sequence created with SERIAL independently from the table it 
is owned by, but not a sequence created by GENERATED ALWAYS AS IDENTITY; you 
need to dump the owning table.  It's easily worked around, but I'm curious why 
that is.

Reply via email to