Skip site navigation (1) Skip section navigation (2)

Update a table from another table

From: Jason Tan Boon Teck <tanboonteck(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Update a table from another table
Date: 2010-11-11 04:25:05
Message-ID: AANLkTik5yLqzacXgwtki5z3fTeacMZ2cROkkzAe3yEpi@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
Hi,


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.

Thanks in advance.


-- 
Jason Tan Boon Teck

Responses

pgsql-novice by date

Next:From: AndreasDate: 2010-11-11 05:15:57
Subject: Re: Update a table from another table
Previous:From: Joshua TolleyDate: 2010-11-10 16:52:06
Subject: Re: PgFouine

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group