Jack Douglas
I have two tables that have deferrable foreign key constraints that refer to each other. I'd like to insert into both of these tables via a function, and it is straightforward to do this with `plpgsql`:
<>https://dbfiddle.uk/?rdbms=postgres_12&fiddle=17387ab8b8ce39c82b055dbc7b25288c
Is there any way of doing the same with a SQL function?
Top Answer
Jack Douglas
I'm not sure this is a sensible general solution as I suspect it may cause concurrency issues, but if you choose a dummy value that will never be present in the table you can insert that, and then update it away again, in a pure `sql` function:
<>https://dbfiddle.uk/?rdbms=postgres_12&fiddle=88f7da708d2eef734400c13accc2e3fc&hide=7