Re: Unable to get UPDATE ... FROM syntax correct - Mailing list pgsql-sql

From Richard Huxton
Subject Re: Unable to get UPDATE ... FROM syntax correct
Date
Msg-id 4B7E69A5.4060705@archonet.com
Whole thread Raw
In response to Unable to get UPDATE ... FROM syntax correct  (Gordon Ross <gr306@ucs.cam.ac.uk>)
Responses Re: Unable to get UPDATE ... FROM syntax correct
List pgsql-sql
On 19/02/10 09:25, Gordon Ross wrote:
>
> UPDATE audit SET key = extension.number FROM extension WHERE audit.record_id
> = extension.number;
>
> But that returns saying "UPDATE 0"

Works here - are you sure you don't have any triggers interfering?

BEGIN;

CREATE TEMP TABLE audit (    id        int,    record_id int,    key       varchar,    PRIMARY KEY (id)
);

CREATE TEMP TABLE extension (    id       int,    number   int,    PRIMARY KEY (id)
);

INSERT INTO audit VALUES (1,1,''), (2,2,''), (3,3,'');
INSERT INTO extension VALUES (-1,1), (-2,2), (-3,3);

UPDATE audit SET key = extension.number
FROM extension
WHERE audit.record_id = extension.number;

SELECT * FROM audit ORDER BY id;

ROLLBACK;

CREATE TABLE
INSERT 0 3
INSERT 0 3
UPDATE 3 id | record_id | key
----+-----------+-----  1 |         1 | 1  2 |         2 | 2  3 |         3 | 3


--   Richard Huxton  Archonet Ltd


pgsql-sql by date:

Previous
From: Gordon Ross
Date:
Subject: Re: Unable to get UPDATE ... FROM syntax correct
Next
From: Richard Huxton
Date:
Subject: Re: sintax error