Re: UPDATE syntax

From: David Greco <David_Greco(at)harte-hanks(dot)com>
To: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: UPDATE syntax
Date: 2012-11-30 13:38:42
Message-ID: 187F6C10D2931A4386EE8E58E13857F6129310A8@BY2PRD0811MB415.namprd08.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Yeah that's good, but there are plenty of columns, was hoping to be able to use (table.*) syntax

-----Original Message-----
From: Albe Laurenz [mailto:laurenz(dot)albe(at)wien(dot)gv(dot)at]
Sent: Friday, November 30, 2012 3:47 AM
To: David Greco; pgsql-general(at)postgresql(dot)org
Subject: RE: [GENERAL] UPDATE syntax

David Greco wrote:
> Need some help with UPDATE syntax. I am attempting to do something
like this:
>
> WITH default_facility AS (
> SELECT facility_id,
> inkjetorlabel
> FROM engagement_facility_defs
> WHERE engagement_facility_def_id = 8
> )
> UPDATE engagement_facilities SET (
> facility_id,
> inkjetorlabel
> )
> = ( default_facility.* )
> FROM default_facility
> WHERE engagement_facilities.engagement_id =3
>
> Postgres errors out on the SET() saying "number of columns does not
match number of values". Also
> tried default_facility.* without the parenthesis but it does not like
that syntax. This example is a
> bit simplified, in reality there are 90 columns in both lists.
>
> Is this syntax not possible? I have rewritten it to this form which
works, but I rather like the CTE
> syntax instead.

The problem seems to be the "*".
It works fine with CTE otherwise:

CREATE TABLE test (id integer primary key, val text); INSERT INTO test VALUES (1, 'something');

WITH cte AS (SELECT 1 AS c1, 'other' AS c2)
UPDATE test SET (id, val) = (cte.c1, CTE.c2)
FROM cte
WHERE id=1;

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message icholy 2012-11-30 14:03:24 Re: libpq - PQsendQuery wait for complete result
Previous Message Henry Drexler 2012-11-30 13:32:22 Re: query performance, though it was timestamps, maybe just table size?