Reputation: 1119
I want to export ONLY the sequences created in a Database created in PostgreSQL. There is any option to do that?
Thank you!
Upvotes: 8
Views: 13459
Reputation: 577
Using DBeaver, you can
crtl-F
to search for the sequences you're interested incrtl-A
to select all of themRight-click
and select Generate SQL -> DDLYou will be given SQL statements to create all of the sequences selected.
Upvotes: -1
Reputation: 73
I know its too old but today I had similar requirement so I tried to solve it the same way by creating a series of "CREATE SEQUENCE" queries which can be used to RE-create sequences on the other DB with bad import (missing sequences) here is the SQL I used:
SELECT
'CREATE SEQUENCE '||c.relname||
' START '||(select setval(c.relname::text, nextval(c.relname::text)-1))
AS "CREATE SEQUENCE SQLs"
FROM
pg_class c
WHERE
c.relkind = 'S'
Maybe that can be helpful for someone.
Upvotes: 5
Reputation: 30362
You could write a query to generate a script that will create your existing sequence objects by querying this information schema view.
select *
from information_schema.sequences;
Something like this.
SELECT 'CREATE SEQUENCE ' || sequence_name || ' START ' || start_value || ';'
from information_schema.sequences;
Upvotes: 14