From: | "Daniel Caune" <daniel(dot)caune(at)ubisoft(dot)com> |
---|---|
To: | <pgsql-sql(at)postgresql(dot)org> |
Subject: | SQL stored function inserting and returning data in a row. |
Date: | 2008-01-11 03:23:20 |
Message-ID: | 1E293D3FF63A3740B10AD5AAD88535D206F416D1@UBIMAIL1.ubisoft.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin pgsql-sql |
Hi,
Is there any way to define a SQL stored function that inserts a row in a
table and returns the serial generated?
CREATE TABLE matchmaking_session
(
session_id bigint NOT NULL DEFAULT
nextval('seq_matchmaking_session_id'),
...
);
CREATE FUNCTION create_matchmaking_sesssion(...)
RETURNS bigint
AS $$
INSERT INTO matchmaking_session(...)
VALUES (...)
RETURNING session_id;
$$ LANGUAGE SQL;
2008-01-10 22:08:48 EST ERROR: return type mismatch in function
declared to return bigint
2008-01-10 22:08:48 EST DETAIL: Function's final statement must be a
SELECT.
2008-01-10 22:08:48 EST CONTEXT: SQL function
"create_matchmaking_sesssion"
I can easily convert this code into a PL/pgSQL function, but I'm
thinking that pure SQL is more natural (and faster?) for such a stored
function.
Regards,
--
Daniel
From | Date | Subject | |
---|---|---|---|
Next Message | Pedro Briones García | 2008-01-11 10:22:02 | PostgreSQL on 64-bit Windows |
Previous Message | Tom Lane | 2008-01-11 00:30:00 | Re: 8.3 RC1 - Logging and filenames |
From | Date | Subject | |
---|---|---|---|
Next Message | Rajesh Kumar Mallah | 2008-01-11 06:58:09 | (possible) bug with constraint exclusion |
Previous Message | Colin Wetherbee | 2008-01-10 22:40:55 | Re: JOIN a table twice for different values in the same query |