Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 5BA152E019E for ; Fri, 11 Jan 2008 07:15:09 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 28124-05 for ; Fri, 11 Jan 2008 07:14:58 -0400 (AST) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.152]) by postgresql.org (Postfix) with ESMTP id 14FFC2E00D1 for ; Fri, 11 Jan 2008 07:15:01 -0400 (AST) Received: by fg-out-1718.google.com with SMTP id 22so1038037fge.23 for ; Fri, 11 Jan 2008 03:15:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=U2gu3SAksl8fX6rn3A3rsYdDnZQ2ZKGvGlNz0AFbMvQ=; b=bZZxMRV++nRHgtbXGmZTGt7/ispfgRCU8WK9TPYWMZhVe57OJgqWlTtXtn6It+Z2prwEM75PJQcfTmiB7l95gJEoU6r7qiRPLzz07+TkFHkEDcG1hGUtZVV6vyLiZer3RzxVYfldOagKzjPxE7ZXZ1vJaTTv4SQ5JHQVsTtpi3k= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=eRXWBclWGhVxedg3jObNG/IsMOYTnYW5Hgb1Yr6HZWAHpQ7JVqWlvzelD4DKtB8KDFzYdE+j39aEplTOuR+1yNq37eu5tIFKrJiiKaBimb6pdyF4Bwd7M0jA18E+pw+mL9QDfBElOlJgxIMdWEH202xbIoyW5Z9NmGhqcF9BdO4= Received: by 10.86.1.1 with SMTP id 1mr2889781fga.2.1200050100712; Fri, 11 Jan 2008 03:15:00 -0800 (PST) Received: by 10.86.80.15 with HTTP; Fri, 11 Jan 2008 03:15:00 -0800 (PST) Message-ID: <179149fe0801110315w24bd1da8lcdd13c8875265f40@mail.gmail.com> Date: Fri, 11 Jan 2008 12:15:00 +0100 From: "=?UTF-8?Q?Marcin_St=C4=99pnicki?=" To: "Daniel Caune" Subject: Re: SQL stored function inserting and returning data in a row. Cc: pgsql-sql@postgresql.org In-Reply-To: <1E293D3FF63A3740B10AD5AAD88535D206F416D1@UBIMAIL1.ubisoft.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <1E293D3FF63A3740B10AD5AAD88535D206F416D1@UBIMAIL1.ubisoft.org> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200801/89 X-Sequence-Number: 29942 On Jan 11, 2008 4:23 AM, 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? Maybe you just need INSERT ... RETURNING? http://www.postgresql.org/docs/8.2/interactive/sql-insert.html " Insert a single row into table distributors, returning the sequence number generated by the DEFAULT clause: INSERT INTO distributors (did, dname) VALUES (DEFAULT, 'XYZ Widgets') RETURNING did; "