1

I want to do some updates, which logically looks like below -

UPDATE    t1 
SET       (x1, x2) = (SELECT  x1, x2 
                              FROM    t1 
                              WHERE id_1 = 8 
                              AND id_2 =1 
                              AND id_3 = 3)
;

But from the documentation it looks like these types of updates are currently not implemented in Postgresql. Is there any workaround for this problem other than the classic style(By classic I meant set x1 = value1, x2=value2,..... style)?

1 Answer 1

3

You can do it:

UPDATE t1 SET x1 = a.x1, x2 = a.x2 FROM 
   (SELECT x1, x2 FROM t1 WHERE id_1 = 8 AND id_2 = 1 AND id_3 = 3) AS a

Aditional condition may be required:

UPDATE t1 SET x1 = a.x1, x2 = a.x2 FROM 
   (SELECT id, x1, x2 FROM t1 WHERE id_1 = 8 AND id_2 = 1 AND id_3 = 3) AS a 
   WHERE a.id = t1.id
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.