Google results on this one are a bit thin, but suggest that it is not easily possible.
My specific problem is that I need to renumber the IDs in two tables that are related to each other such that table B has an ‘table_a_id’ column in it. I can’t renumber table A first because then its children in B point to the old IDs. I can’t renumber table B first because then they would point to the new IDs before they were created. Now repeat for three or four tables.
I don’t really want to have to fiddle around with individual relationships when I could just ‘start transaction; disable ref integrity; sort IDs out; re-enable ref integrity; commit transaction’. Mysql and MSSQL both provide this functionality IIRC so I would be surprised if Postgres didn’t.
Thanks!
It does not seem possible. Other suggestions almost always refer to dropping the constraints and recreating them after work is done.
However, it seems you can make constraints
DEFERRABLE, such that they are not checked until the end of a transaction. See PostgreSQL documentation forCREATE TABLE(search for ‘deferrable’, it’s in the middle of the page).