It is somewhat abandoned.
How to perform and update with a join using CTE’s in postgres
with replacement as (
select value, condtion1, condtion2 from somewhere
where x= something
)select * from replacement
The cte might seem verbose, but I’m going to need it later, and it helps my sql stay organized
BEGIN;
with replacement as (
select value, condtion1, condtion2 from somewhere
where x= something
)
update "LongName" as shortname
set value = replacement.value
from replacement
where shortname.condtion1 = replacement.condtion1
and shortname.condtion2 = replacement.condition2;
-- Test query for manually confirming the results look like what you were expecting
SELECT value, condition1, condition2 from "LongName" shortname
where x=something
ROLLBACK;
If the select result looks good, you can run it without the transaction to update.
with replacement as (
select value, condtion1, condtion2 from somewhere
where x= something
)
update "LongName" as shortname
set value = replacement.value
from replacement
where shortname.condtion1 = replacement.condtion1
and shortname.condtion2 = replacement.condition2;