From: Gerardo Herzig <gherzig@fmed.uba.ar>
To: Daniel Caune <daniel.caune@ubisoft.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: SQL stored function inserting and returning data in a row.
Date: Fri, 11 Jan 2008 08:03:07 -0300
Message-ID: <47874CEB.3010803@fmed.uba.ar> (raw)
In-Reply-To: <1E293D3FF63A3740B10AD5AAD88535D206F416D1@UBIMAIL1.ubisoft.org>
References: <1E293D3FF63A3740B10AD5AAD88535D206F416D1@UBIMAIL1.ubisoft.org>
Daniel Caune wrote:
>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"
>
>
>
What about
$$
INSERT INTO .... ;
select currval('seq_matchmaking_session_id');
$$ language sql;
?
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: gherzig@fmed.uba.ar, daniel.caune@ubisoft.com
Subject: Re: SQL stored function inserting and returning data in a row.
In-Reply-To: <47874CEB.3010803@fmed.uba.ar>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox