From: Ian Barwick <barwick@gmx.net>
To: David Durst <ddurst@la-rubber.com>
To: pgsql-sql@postgresql.org
Subject: Re: Insert Function
Date: Wed, 10 Jul 2002 22:45:44 +0200
Message-ID: <200207102245.44221.barwick@gmx.net> (raw)
In-Reply-To: <1220.10.1.1.39.1026331164.squirrel@www.la-rubber.com>
References: <1220.10.1.1.39.1026331164.squirrel@www.la-rubber.com>
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
'INSERT INTO usr
(user_name,first_name,last_name,permission_set_id,customer_id)
VALUES
($1,$2,$3,$4,$5);
SELECT ''created user ''|| $1::VARCHAR'
language 'sql';
HTH
Ian Barwick
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: barwick@gmx.net, ddurst@la-rubber.com
Subject: Re: Insert Function
In-Reply-To: <200207102245.44221.barwick@gmx.net>
* 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