I attempted to use a Common Table Expression (CTE) to update a table in PostgreSQL with the following query:
WITH TMP AS (
INSERT INTO TABLE1 (...)
SELECT (...) FROM TABLE2
RETURNING *)
UPDATE TABLE1
SET COLUMN1 = CONCAT(TMP.C1,TMP.C2)
FROM TMP
WHERE TMP.ID = TABLE1.ID
While the CTE is formed correctly (verified by running SELECT * FROM TMP), the UPDATE statement doesn't seem to execute as expected. Running SELECT * FROM TMP JOIN TABLE1 ON TABLE1.ID = TMP.ID returns an empty result.
Could you please help me identify why the UPDATE statement is not working as intended?
WITH TMP ABS ...being correct syntax. 2) Why not doCONCAT(C1,C2)as part of the insert?