UPDATE syntax

From: David Greco <David_Greco(at)harte-hanks(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: UPDATE syntax
Date: 2012-11-29 15:57:35
Message-ID: 187F6C10D2931A4386EE8E58E13857F612930DC9@BY2PRD0811MB415.namprd08.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.

UPDATE engagement_facilities SET (
facility_id,
inkjetorlabel
)
= ( df.facility_id, df.inkjetorlabel )
FROM engagement_facility_defs df
WHERE engagement_facility_def_id = 8
AND engagement_facilities.engagement_id =3

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter Kroon 2012-11-29 16:01:25 set value var via execute
Previous Message Chris Angelico 2012-11-29 15:30:43 Re: youtube video on pgsql integrity