Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting sequences in PostgreSQL

Tags:

postgresql

I want to export ONLY the sequences created in a Database created in PostgreSQL. There is any option to do that?

Thank you!

like image 229
user1702964 Avatar asked Dec 04 '12 11:12

user1702964


People also ask

How do I back up a sequence in PostgreSQL?

Using pg_dump CREATE TABLE foo ( id serial PRIMARY KEY, other int ); INSERT INTO foo (other) VALUES (1),(2),(3); Then dump it with pg_dump or pg_dumpall , $ pg_dump -t foo | grep -i pg_catalog. setval | grep "'public.

Does PostgreSQL have sequence?

A sequence in PostgreSQL is a user-defined schema-bound object that generates a sequence of integers based on a specified specification. To create a sequence in PostgreSQL, you use the CREATE SEQUENCE statement.


1 Answers

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;
like image 104
Kuberchaun Avatar answered Sep 19 '22 17:09

Kuberchaun