[Pgsql-ayuda] update exists

Alvaro Herrera alvherre@dcc.uchile.cl
Thu, 23 Oct 2003 14:37:47 -0300


On Thu, Oct 24, 2002 at 05:15:05PM +0100, Xavi Puig wrote:
> Perd?n, se me habia olvidado la query:
> 
> UPDATE tab1 SET col20=false WHERE exists (select * from (select * from tab1 where col20=true) as alias0,tab2,tab3 where (tab2.col2=tab3.col1 and tab3.col2=alias0.col1) and ( tab2.col2=20500))

Hmm... que tuplas se supone que tiene que actualizar?  Como estas
uniendo tab1 con la subconsulta?  Me parece sospechoso esto, estas
seguro que es correcto?  Intenta reescribirlo.

update tab1 set col20=false from tab3
where
	tab3.col1=20500 and
	tab3.col2=tab1.col1 and
	tab1.col20=true

No es equivalente?  No estoy seguro pero me parece que si ...

-- 
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
Dios hizo a Adán, pero fue Eva quien lo hizo hombre.