Re: Return Record

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: Return Record
Дата
Msg-id 200306070946.05646.dev@archonet.com
обсуждение исходный текст
Ответ на Return Record  (Rory Campbell-Lange <rory@campbell-lange.net>)
Список 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 по дате отправления:

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: Backups and restores.
Следующее
От: "Shridhar Daithankar"
Дата:
Сообщение: Re: How to merge 3 databases in one database quickly