Re: Return Record

From: Richard Huxton <dev(at)archonet(dot)com>
To: Rory Campbell-Lange <rory(at)campbell-lange(dot)net>, pgsql-general(at)postgresql(dot)org
Subject: Re: Return Record
Date: 2003-06-07 08:46:05
Message-ID: 200306070946.05646.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-novice

On Friday 06 Jun 2003 4:20 pm, Rory Campbell-Lange wrote:
> I'm not clear on how to handle returning a record from a function.
> I have planned a function that is handed two strings and returns two
> integers. I need to return errors that satisfy the return type. At the
> moment my "RETURN 0;" lines result in "return type mismatch..." errors.

> CREATE OR REPLACE FUNCTION fn_b1_login2
> (varchar, varchar) RETURNS record
...
> IF email IS NULL THEN
> RAISE EXCEPTION ''no email found at fn_e3_person_register'';
> RETURN (0, 0);
> END IF;
...
> RETURN recone;

OK - I think what you probably want to do is define a new type login_results
(CREATE TYPE login_results (n_id int, bid int)) and return that rather than
"record".

Then, I'd just set both fields of "recone" to null and return that during
error checks. It doesn't really matter what values you use since the
exception will kill the transaction anyway, but null seems better than 0.

--
Richard Huxton

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2003-06-07 08:52:36 Re: Backups and restores.
Previous Message Shridhar Daithankar 2003-06-07 08:43:15 Re: How to merge 3 databases in one database quickly

Browse pgsql-novice by date

  From Date Subject
Next Message Joe Conway 2003-06-07 16:05:37 Re: Return Record
Previous Message Jeff Eckermann 2003-06-06 23:40:09 Re: FATAL 1