From: | "Alain Roger" <raf(dot)news(at)gmail(dot)com> |
---|---|
To: | "Craig Ringer" <craig(at)postnewspapers(dot)com(dot)au> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: returned value from SQL statement |
Date: | 2008-03-27 10:25:18 |
Message-ID: | 75645bbb0803270325o4cff3325t14ce0abccc304e40@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
not really.. but it is true that it can be confusing...sorry :-(
the purpose here, it is to solve my problem with a transaction inside a
function.
i need to know if there is a common return value for error in case of a SQL
statement failed.
it seems that not, so i would like to know if the rollback inside an
EXCEPTION block is the best practice.
here is an example :
> CREATE OR REPLACE FUNCTION cust_portal.sp_u_003(usrname character varying,
> firstname character varying, email character varying, nl_reg boolean,
> nl_lang character varying)
> RETURNS integer AS
> $BODY$
>
> DECLARE
>
> existing_email INTEGER := 0;
>
> BEGIN
> set search_path = cust_portal;
>
> SELECT count(*) INTO existing_email FROM users WHERE users.email =
> email;
> IF (existing_email != 0) THEN
> RETURN (-1);
> ELSE
> -- BEGIN TRANSACTION;
> INSERT INTO cust_portal.users VALUES
> (
> nextval('users_usr_id_seq'),
> usrname,
> firstname,
> email,
> nlreg,
> nl_lang
> );
>
> DELETE FROM cust_portal.tmp_newsletterreg WHERE
> tmp_newsletterreg.email = email;
>
> COMMIT;
> RETURN(0);
>
> EXCEPTION
> ROLLBACK;
> RETURN(-2);
>
> END IF;
> END;
>
moreover such code generates an error :
On Thu, Mar 27, 2008 at 10:55 AM, Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
wrote:
> Alain Roger wrote:
> > sorry... under pl/pgsql as stored procedure
>
> Then this question was already asked and answered less than a week ago
> on this mailing list.
>
> By you, with almost exactly the same subject line.
>
> Forgive my confusion, but why are you asking the same question again?
> What's changed since last time? What else do you need to know?
>
> --
> Craig Ringer
>
--
Alain
------------------------------------
Windows XP SP2
PostgreSQL 8.2.4 / MS SQL server 2005
Apache 2.2.4
PHP 5.2.4
C# 2005-2008
From | Date | Subject | |
---|---|---|---|
Next Message | Volkan YAZICI | 2008-03-27 11:06:01 | Re: Performance of update |
Previous Message | Craig Ringer | 2008-03-27 09:55:32 | Re: returned value from SQL statement |