Received: from post.webmailer.de (natpost.webmailer.de [192.67.198.65]) by postgresql.org (Postfix) with ESMTP id BB00047595B for ; Wed, 10 Jul 2002 16:44:30 -0400 (EDT) Received: from ianb (pD9EB105A.dip.t-dialin.net [217.235.16.90]) by post.webmailer.de (8.9.3/8.8.7) with ESMTP id WAA11472; Wed, 10 Jul 2002 22:44:23 +0200 (MET DST) Content-Type: text/plain; charset="iso-8859-1" From: Ian Barwick To: "David Durst" , Subject: Re: Insert Function Date: Wed, 10 Jul 2002 22:45:44 +0200 X-Mailer: KMail [version 1.4] References: <1220.10.1.1.39.1026331164.squirrel@www.la-rubber.com> In-Reply-To: <1220.10.1.1.39.1026331164.squirrel@www.la-rubber.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200207102245.44221.barwick@gmx.net> X-Archive-Number: 200207/146 X-Sequence-Number: 8525 On Wednesday 10 July 2002 21:59, David Durst wrote: > Is there anyway to create a insert function? > I am trying: > CREATE FUNCTION add_user(varchar(20),varchar(20),varchar(20),int4,int4) > RETURNS int4 AS 'INSERT INTO usr > (user_name,first_name,last_name,permission_set_id,customer_id) values > ($1,$2,$3,$4,$5)' language 'sql'; > > and get: > > ERROR: function declared to return integer, but final statement is not a > SELECT > I thought that a insert would return a internal row #, but I am not sure > about this. You can do something like this: CREATE FUNCTION add_user(varchar(20),varchar(20),varchar(20),int4,int4) RETURNS VARCHAR AS=20 'INSERT INTO usr (user_name,first_name,last_name,permission_set_id,customer_id)=20 VALUES ($1,$2,$3,$4,$5); SELECT ''created user ''|| $1::VARCHAR' language 'sql'; HTH Ian Barwick