SQL stored function inserting and returning data in a row. - Mailing list pgsql-sql

From Daniel Caune
Subject SQL stored function inserting and returning data in a row.
Date
Msg-id 1E293D3FF63A3740B10AD5AAD88535D206F416D1@UBIMAIL1.ubisoft.org
Whole thread Raw
Responses Re: SQL stored function inserting and returning data in a row.  (Gerardo Herzig <gherzig@fmed.uba.ar>)
Re: SQL stored function inserting and returning data in a row.  ("Marcin Stępnicki" <mstepnicki@gmail.com>)
Re: SQL stored function inserting and returning data in a row.  ("Marcin Stępnicki" <mstepnicki@gmail.com>)
List 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


pgsql-sql by date:

Previous
From: Colin Wetherbee
Date:
Subject: Re: JOIN a table twice for different values in the same query
Next
From: "Rajesh Kumar Mallah"
Date:
Subject: (possible) bug with constraint exclusion