Re: UPDATE of several columns using SELECT statement

Поиск
Список
Период
Сортировка
От Sam Mason
Тема Re: UPDATE of several columns using SELECT statement
Дата
Msg-id 20090317152522.GB32672@frubble.xen.chris-lamb.co.uk
обсуждение исходный текст
Ответ на UPDATE of several columns using SELECT statement  ("adam.slachta" <adam.slachta@xitee.com>)
Список pgsql-general
On Tue, Mar 17, 2009 at 03:55:47PM +0100, adam.slachta wrote:
> 1. When trying to update two columns
>
> UPDATE myFirstTable SET (fistCol, secCol) = (  SELECT anotherFistCol, anotherSecondCol FROM mySecondTable )

The more common say of expressing this would be something like:

  UPDATE myFirstTable a SET
      fistCol = b.anotherFistCol,
      secCol  = b.anotherSecondCol
    FROM mySecondTable b
    WHERE a.expr = b.expr;

> 2. When changed to (only the parentheses are changed):
>
> UPDATE myFirstTable SET (fistCol, secCol) = ((SELECT anotherFistCol, anotherSecondCol FROM mySecondTable ))
>
> I am getting: ERROR:  number of columns does not match number of values

PG is somewhat ad-hoc with its support of its record syntax and
unfortunately doesn't support the above at the moment.  The error is
coming from very early on (I think maybe when parsing) and I don't think
it ever gets as far as checking that the value coming back from the
select is a record of the same structure as is on the left hand side.

--
  Sam  http://samason.me.uk/

В списке pgsql-general по дате отправления:

Предыдущее
От: Neanderthelle Jones
Дата:
Сообщение: Re: Escaping special characters
Следующее
От: Ivano Luberti
Дата:
Сообщение: Re: COPY command question