Re: RAISE with C?

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Elliot Chance <elliotchance(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: RAISE with C?
Date: 2010-12-20 08:14:29
Message-ID: AANLkTikk_FBkXnmP6B_H7AGEMKBn1oRJYnpibGOFmxq0@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello

2010/12/20 Elliot Chance <elliotchance(at)gmail(dot)com>:
> Hi,
>
> Is it possible to do the equivalent of RAISE EXCEPTION inside a C-function? Like this:
>
>

sure, there are functions elog and ereport

Regards

Pavel Stehule

> PG_FUNCTION_INFO_V1(check_something);
> Datum check_something(PG_FUNCTION_ARGS)
> {
>        // RAISE EXCEPTION 'bla bla'
> }
>
> CREATE OR REPLACE FUNCTION do_check() RETURNS text AS $$
> BEGIN
>        PERFORM check_something();
>        RETURN 'All good';
> EXCEPTION
>        WHEN RAISE EXCEPTION THEN
>                RETURN 'Something bad';
> END;
> $$ LANGUAGE plpgsql IMMUTABLE;
>
>
> That code may not work but you get the idea, I want to throw an exception from a C function that can be caught in PL/pgSQL. Also is it further possible to catch the message that RAISE EXCEPTION sends? Like 'Something bad: bla bla'
>
> Thanks,
> Elliot
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Raimon Fernandez 2010-12-20 08:28:59 pg_restore 8.x to postgreSQL 9.x functions and triggers aren't created
Previous Message Elliot Chance 2010-12-20 08:10:52 RAISE with C?