I have this issue where if there is no record in copy_on_write.id
then the UPDATE listings SET images = (SELECT images FROM new_vals)
runs and wipes out listings.images
with nothing.
So, I am trying to use a condition to only run the UPDATE listings
if copy_on_write.images
exist.
right now I get:
psql:queries/copy-to-source.sh:20: ERROR: syntax error at or near "CASE"
LINE 10: CASE WHEN images <>
WITH
new_vals AS (
SELECT *
FROM copy_on_write
WHERE copy_on_write.posted_by = 102550922::text
AND copy_on_write.id = 4
),
updates AS (
SELECT images FROM new_vals,
CASE WHEN images <> ''
THEN UPDATE listings SET images = (SELECT images FROM new_vals)
END
)
SELECT internal_id FROM new_vals