goqu
goqu copied to clipboard
PostgreSQL. DELETE FROM ... USING
Hi! I need to build following query:
DELETE FROM table1 t1 USING (SELECT id FROM table2) AS t2 WHERE t1.tab2_id = t2.id
But DeleteDataset does not have method Using
.
How can I achieve my goal?
The same query could also be expressed as:
DELETE FROM table1 t1 WHERE t1.id IN (SELECT id from table2)
Sorry to bump, but I also am interested with how to use the USING feature of Postgres. @abdusco your example does not help the case where you want to use a column from the other table in the RETURNING clause.
Example: https://dbfiddle.uk/spBZMg5R
DELETE FROM a
USING b
WHERE a.cluster = b.cluster AND a.cluster = 10
RETURNING a.id, b.val;