List all sequences in a Postgres db 8.1 with SQL

后端 未结 19 1741
旧时难觅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:02

    This statement lists the table and column that is associated with each sequence:

    Code:

        SELECT t.relname as related_table, 
               a.attname as related_column,
               s.relname as sequence_name
        FROM pg_class s 
          JOIN pg_depend d ON d.objid = s.oid 
          JOIN pg_class t ON d.objid = s.oid AND d.refobjid = t.oid 
          JOIN pg_attribute a ON (d.refobjid, d.refobjsubid) = (a.attrelid, a.attnum)
          JOIN pg_namespace n ON n.oid = s.relnamespace 
        WHERE s.relkind     = 'S' 
    
      AND n.nspname     = 'public'
    

    more see here link to answer

提交回复
热议问题