From: | "David Johnston" <polobo(at)yahoo(dot)com> |
---|---|
To: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Function Column Expansion Causes Inserts To Fail |
Date: | 2011-05-30 21:09:45 |
Message-ID: | 000001cc1f0d$e704f740$b50ee5c0$@yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
PostgreSQL 9.0.4
The following script fails even though the "pkonlytest" table is empty since
we just created it.
>>>>>>>>>>>>>>>>>>>>>>>>>> BEGIN SCRIPT
CREATE TABLE pkonlytest (
pkid text PRIMARY KEY
);
CREATE OR REPLACE FUNCTION createpkrecord(INOUT pkvalue text, OUT col1
boolean, OUT col2 boolean)
RETURNS record
AS $$
BEGIN
INSERT INTO pkonlytest (pkid) VALUES (pkvalue);
col1 = true;
col2 = false;
END;
$$
LANGUAGE 'plpgsql';
SELECT ( createpkrecord('1') ).*;
SQL Error: ERROR: duplicate key value violates unique constraint
"pkonlytest_pkey"
DETAIL: Key (pkid)=(1) already exists.
CONTEXT: SQL statement "INSERT INTO pkonlytest (pkid) VALUES (pkvalue)"
PL/pgSQL function "createpkrecord" line 2 at SQL statement
>>>>>>>>>>>>>>>>>>END SCRIPT
If you call the function without the column expansion (and required
parentheses) it work just fine.
SELECT createpkrecord('1');
There is a workaround.
SELECT (func.result).* FROM (
SELECT createpkrecord('4') as result ) func
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | Craig Ringer | 2011-05-30 23:17:37 | Re: determine database and tables from deadlock |
Previous Message | Carlos Sotto Maior (SIM) | 2011-05-30 18:35:39 | RES: SELECT COUNT(*) execution time on large tables (v9.0.4-1) |