Re: Select into
От | Craig Ringer |
---|---|
Тема | Re: Select into |
Дата | |
Msg-id | 47E25D55.9070908@postnewspapers.com.au обсуждение исходный текст |
Ответ на | Re: Select into (Gavin 'Beau' Baumanis <gavinb@eclinic.com.au>) |
Список | pgsql-sql |
> > >> craig=# update x set val = foundrow.val from ( select val from x >> where id = 2 ) as foundrow where id = 1 ; >> UPDATE 1 >> > Thinking about it, it'd actually be better written as: UPDATE x SET val = foundrow.val FROM ( SELECT val FROM x AS x2 WHERE x2.id = 2 ) AS foundrow WHERE id = 1; ... because it's nicer to use a table alias for x within the subquery and elimate any ambiguity for the reader about which "id" you're referring to. After all, it's also valid to reference the "id "field of the "x" outside the subquery within it, like in the following valid but rather nonsensical query: UPDATE x SET val = (SELECT id+1) WHERE id = 1; Using the table alias will not change the query plan at all, it just makes the reference to "id" within the subquery unambiguous to the reader. Sorry for the repeat post. -- Craig Ringer
В списке pgsql-sql по дате отправления: