Re: Return Record - Mailing list pgsql-general

From Richard Huxton
Subject Re: Return Record
Date
Msg-id 200306070946.05646.dev@archonet.com
Whole thread Raw
In response to Return Record  (Rory Campbell-Lange <rory@campbell-lange.net>)
List pgsql-general
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

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Backups and restores.
Next
From: "Shridhar Daithankar"
Date:
Subject: Re: How to merge 3 databases in one database quickly