Referring to the syntax for updating a table from a temp table at "Update a field in a table using a value from another table ..." at

http://www.cryer.co.uk/brian/sql/sql_crib_sheet.htm



Is this the correct syntax for PG for updating a table from a temp table?

Search Discussions

  • Thom Brown at Aug 17, 2010 at 6:22 pm

    On 17 August 2010 19:09, Charles Holleran wrote:
    Referring to the syntax for updating a table from a temp table at "Update a
    field in a table using a value from another table ..." at
    http://www.cryer.co.uk/brian/sql/sql_crib_sheet.htm

    Is this the correct syntax for PG for updating a table from a temp table?
    No, you need to use a FROM clause if you wish to update based on another table.

    Taking the example from that page you linked to:

    UPDATE tableone
    SET field1 = tabletwo.fieldx
    FROM tabletwo
    WHERE tableone.commonid = tabletwo.commonid;

    Look at http://www.postgresql.org/docs/current/static/sql-update.html
    for more information.

    Regards
    --
    Thom Brown
    Registered Linux user: #516935
  • Charles Holleran at Aug 17, 2010 at 7:41 pm
    Thanks.


    -----Original Message-----
    From: Thom Brown <thom@linux.com>
    Date: Tue, 17 Aug 2010 18:20:58
    To: <scorpdaddy@hotmail.com>
    Cc: <pgsql-novice@postgresql.org>
    Subject: Re: [NOVICE] update a table from a temp table
    On 17 August 2010 19:09, Charles Holleran wrote:
    Referring to the syntax for updating a table from a temp table at "Update a
    field in a table using a value from another table ..." at
    http://www.cryer.co.uk/brian/sql/sql_crib_sheet.htm

    Is this the correct syntax for PG for updating a table from a temp table?
    No, you need to use a FROM clause if you wish to update based on another table.

    Taking the example from that page you linked to:

    UPDATE tableone
    SET field1 = tabletwo.fieldx
    FROM tabletwo
    WHERE tableone.commonid = tabletwo.commonid;

    Look at http://www.postgresql.org/docs/current/static/sql-update.html
    for more information.

    Regards
    --
    Thom Brown
    Registered Linux user: #516935

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppgsql-novice @
categoriespostgresql
postedAug 17, '10 at 6:09p
activeAug 17, '10 at 7:41p
posts3
users2
websitepostgresql.org
irc#postgresql

2 users in discussion

Charles Holleran: 2 posts Thom Brown: 1 post

People

Translate

site design / logo © 2022 Grokbase