I want to export ONLY the sequences created in a Database created in PostgreSQL. There is any option to do that?
Thank you!
I want to export ONLY the sequences created in a Database created in PostgreSQL. There is any option to do that?
Thank you!
您可以编写一个查询来生成一个脚本,该脚本将通过查询此信息模式视图来创建您现有的序列对象。
select *
from information_schema.sequences;
像这样的东西。
SELECT 'CREATE SEQUENCE ' || sequence_name || ' START ' || start_value || ';'
from information_schema.sequences;
我知道它太旧了,但今天我有类似的要求,所以我尝试通过创建一系列“CREATE SEQUENCE”查询以相同的方式解决它,这些查询可用于在导入错误的其他数据库上重新创建序列(缺少序列)这是我使用的 SQL:
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'
也许这对某人有帮助。
使用 DBeaver,您可以
crtl-F
搜索您感兴趣的序列crtl-A
选择所有这些Right-click
并选择生成 SQL -> DDL您将获得 SQL 语句来创建所有选定的序列。