tags:

views:

40

answers:

1

Hi, 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)?

+3  A: 

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
valodzka
Thank you very much....
Night Shade