List all sequences in a Postgres db 8.1 with SQL

后端 未结 19 1732
旧时难觅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条回答
  •  Happy的楠姐
    2020-12-12 11:46

    The following query gives names of all sequences.

    SELECT c.relname FROM pg_class c WHERE c.relkind = 'S';
    

    Typically a sequence is named as ${table}_id_seq. Simple regex pattern matching will give you the table name.

    To get last value of a sequence use the following query:

    SELECT last_value FROM test_id_seq;
    

提交回复
热议问题