List all sequences in a Postgres db 8.1 with SQL

后端 未结 19 1780
旧时难觅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 -d -t -c "SELECT 'SELECT ''' || c.relname || ''' as sequence_name, last_value FROM ' || c.relname || ';' FROM pg_class c WHERE (c.relkind = 'S')" | psql -U -d -t

提交回复
热议问题