Re: Can I use pg_dump to save a sequence for a table that is not also being saved? - Mailing list pgsql-general

From Adrian Klaver
Subject Re: Can I use pg_dump to save a sequence for a table that is not also being saved?
Date
Msg-id 4f3fce72-042a-45e5-b5af-186876a02de1@aklaver.com
Whole thread Raw
In response to Re: Can I use pg_dump to save a sequence for a table that is not also being saved?  (Shaheed Haque <shaheedhaque@gmail.com>)
List pgsql-general

On 3/17/26 10:28 AM, Shaheed Haque wrote:
> Hi Adrian,
> 
> Thanks for the kind replies, but it seems my email was not very clear...
> 
> I was hoping, possibly foolishly, that specifying the wildcard in "-- 
> table=public.*id_seq" would dump the  matched sequences, irrespective of 
> whether the associated table data was being dumped. Is there a way to 
> get just the sequences?

1) You are using --data-only which means you won't get the sequence 
definition, only the statement to set the sequence value:

SELECT pg_catalog.setval('public.seq_test_line_id_seq', 1, false);

If the sequence is not already in the database instance the above will fail.

2) Sequences are an object that can be created as a stand alone which 
you then use as needed or more generally these days as a dependent 
object to a serial 'type' or a GENERATED ALWAYS AS IDENTITY attribute to 
a column. In the latter cases the table needs to exist for the sequence 
to have any relevance. In your case I'm thinking that the sequences you 
want are tied to tables and in the case where you don't dump the 
associated table the sequence data(pg_catalog.setval(...)) is not dumped 
as there is no point.

> 
> It is very possible that I am barking up the wrong tree with pg_dump, 
> and what I need is some queries using the information_schema.

I'm going to say yes you will need to find another method. It would help 
to know exactly what it is you want.
> 
> Thanks, Shaheed

>     -- 
>     Adrian Klaver
>     adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>
> 




pgsql-general by date:

Previous
From: Greg Hennessy
Date:
Subject: help debugging an issue with selectivity
Next
From: Adrian Klaver
Date:
Subject: Trying to understand pg_get_expr()