List all sequences in a Postgres db 8.1 with SQL

后端 未结 19 1710
旧时难觅i
旧时难觅i 2020-12-12 11:30

I\'m converting a db from postgres to mysql.

Since i cannot find a tool that does the trick itself, i\'m going to convert all postgres sequences to autoincrement id

相关标签:
19条回答
  • 2020-12-12 12:07

    Here is an example how to use psql to get a list of all sequences with their last_value:

    psql -U <username> -d <database> -t -c "SELECT 'SELECT ''' || c.relname || ''' as sequence_name, last_value FROM ' || c.relname || ';' FROM pg_class c WHERE (c.relkind = 'S')" | psql -U <username> -d <database> -t

    0 讨论(0)
提交回复
热议问题