Deleting a table in PostgreSQL without deleting an associated sequence

前端 未结 1 1918
没有蜡笔的小新
没有蜡笔的小新 2021-02-12 23:51

I have a table, foo. For the purposes of a quick upgrade/deploy of my site, I made a new table, tmp_foo, to contain some new data, by doing:

         


        
1条回答
  •  再見小時候
    2021-02-13 00:27

    Try this:

    ALTER SEQUENCE foo_id_seq OWNED BY NONE
    

    then you should be able to drop the table.

    To retrieve the "owner" of a sequence use the following query

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

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