From: | Iain Barnett <iainspeed(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | INSERT... RETURNING with a function |
Date: | 2009-09-26 18:04:42 |
Message-ID: | B5461E06-CAF0-4CA6-8F98-85CB35AFE2AA@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I've written a straightforward insert function, but using the
RETURNING keyword for the first time. If I try running the test case
I get the error:
ERROR: query has no destination for result data
CONTEXT: PL/pgSQL function "nonauth_users_insert_new_udf" line 7 at
SQL statement
I'm not sure what I need to do to catch the return value as I've
tried a few different combinations and nothing has worked for me so
far. The Insert statement as it is below but outside of a function
works and returns the id. Any input is much appreciated.
I'm running version 8.4
Regards,
Iain
/*test*/
/*
select nonauth_users_insert_new_udf(
'testuser1', 'testuser1(at)example(dot)com', 'xDvTfTOB99mG6zSyMjYtVhUd3P4',
'4DhFLU1YJU5Oz/+XGqh3npn2RJQ'
);
*/
CREATE OR REPLACE FUNCTION nonauth_users_insert_new_udf(
_username varchar
, _emailaddress varchar
, _salt char
, _hash char
) RETURNS int
AS $$
BEGIN
Insert into nonauth_users ( username, emailaddress, salt, hash,
added )
values ( _username, _emailaddress, _salt, _hash, now() )
RETURNING nonauth_users_id;
--the query works this way though
--RETURN currval(pg_get_serial_sequence('nonauth_users',
'nonauth_users_id'));
END;
$$
LANGUAGE plpgsql;
From | Date | Subject | |
---|---|---|---|
Next Message | Zdenek Kotala | 2009-09-26 18:09:58 | Re: Solaris Postgres |
Previous Message | John R Pierce | 2009-09-26 17:57:27 | Re: Solaris Postgres |