Fork me on GitHub
#sql
<
2019-12-29
>
grav19:12:45

Not exactly Clojure-specific, hope that's alright :-) I have a table b that's effectively an exclusion filter for another table a, so it's storing the primary key of rows that I want to exclude. Upon selection from a, I want to update b with the primary key from the retrieved rows, but I also want to return the rows from a. With Postgres I can do something like

INSERT INTO b
SELECT id FROM a LEFT JOIN b ON a.id=b.id WHERE b.id IS NULL
RETURNING *
But then if I want to select anything else than id from a, it won't work. Is there (with Postgres) a way of selecting multiple columns from a and updating b with only id in one statement? Edit: This looks promising: https://dba.stackexchange.com/a/90215/111942 Something like
WITH ins(id) AS ( [stmt above ] ) SELECT ins.id, ... FROM ins JOIN a on a.id=ins.id