Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id B54FB2E0112 for ; Thu, 10 Jan 2008 23:23:28 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 48780-01 for ; Thu, 10 Jan 2008 23:23:06 -0400 (AST) Received: from relay02.mdc.ubisoft.com (relay02.mdc.ubisoft.com [216.98.56.135]) by postgresql.org (Postfix) with ESMTP id 9FF642E2D91 for ; Thu, 10 Jan 2008 23:23:24 -0400 (AST) Received: from mdc-owa01.ubisoft.org (srvowa1-mdc.ubisoft.org [10.129.1.20]) by smarthost.mdc.ubisoft.com (Postfix) with ESMTP id 6FFC34C007 for ; Thu, 10 Jan 2008 22:23:06 -0500 (EST) Received: from UBIMAIL1.ubisoft.org ([10.129.1.15]) by mdc-owa01.ubisoft.org with Microsoft SMTPSVC(6.0.3790.1830); Thu, 10 Jan 2008 22:23:21 -0500 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: SQL stored function inserting and returning data in a row. Date: Thu, 10 Jan 2008 22:23:20 -0500 Message-ID: <1E293D3FF63A3740B10AD5AAD88535D206F416D1@UBIMAIL1.ubisoft.org> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: SQL stored function inserting and returning data in a row. Thread-Index: AchUAVC7/xR9p7UoSEyCed5/XhIjwQ== From: "Daniel Caune" To: X-OriginalArrivalTime: 11 Jan 2008 03:23:21.0107 (UTC) FILETIME=[51056E30:01C85401] X-Ubisoft-MailScanner-Information: Please contact administrators@ubisoft.qc.ca X-Ubisoft-MailScanner: Found to be clean X-Ubisoft-MailScanner-SpamCheck: X-MailScanner-From: daniel.caune@ubisoft.com X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200801/84 X-Sequence-Number: 29937 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; =20 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