Re: Update a table from another table

Поиск
Список
Период
Сортировка
От Andreas
Тема Re: Update a table from another table
Дата
Msg-id 4CDB7C0D.3000400@gmx.net
обсуждение исходный текст
Ответ на Update a table from another table  (Jason Tan Boon Teck <tanboonteck@gmail.com>)
Ответы Re: Update a table from another table  (Jason Tan Boon Teck <tanboonteck@gmail.com>)
Список pgsql-novice
Am 11.11.2010 05:25, schrieb Jason Tan Boon Teck:
> I am trying to update tableA with records from tableB, in a single SQL
> statement, along the lines of
>
> INSERT INTO tablea SELECT * FROM tableb;
>
> but doing UPDATE instead. The manual says
>
> UPDATE [ ONLY ] table [ [ AS ] alias ]
>      SET { column = { expression | DEFAULT } |
>            ( column [, ...] ) = ( { expression | DEFAULT } [, ...] ) } [, ...]
>      [ FROM from_list ]
>      [ WHERE condition | WHERE CURRENT OF cursor_name ]
>      [ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]
>
> I am having trouble defining the SET part of the statement. The table
> has many columns. Is there a wild card or something.

There is no wildcard mentioned besides the one in the last line, but
this refers to the columns you might want to get returned after the update.

In case you want to replace the whole contents of records you may try to
delete the records in tableA and then reinsert them out of your tableB.
Though this wont work if some other tables have foreign keys of tableA.


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

Предыдущее
От: Jason Tan Boon Teck
Дата:
Сообщение: Update a table from another table
Следующее
От: Andreas
Дата:
Сообщение: Re: How to do A union (B - ( A intersect B )) or sort of :-)