Re: How to raise error from PostgreSql SQL statement if some condition is met

From: Craig Ringer <ringerc(at)ringerc(dot)id(dot)au>
To: Andrus <kobruleht2(at)hot(dot)ee>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: How to raise error from PostgreSql SQL statement if some condition is met
Date: 2012-08-12 12:53:20
Message-ID: 5027A740.6000805@ringerc.id.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 08/12/2012 06:02 PM, Andrus wrote:
>> ... RaiseException(text, variadic text[])
>> ..
>
>> VARIADIC is keyword, not datatype
>
> Thank you.
>
> I tried code below but got error shown in comment.
> No idea what I'm doing wrong.
>
> Andrus.
>
>
> CREATE OR REPLACE FUNCTION RaiseException(text, variadic text[] )
> RETURNS void LANGUAGE plpgsql AS
> $BODY$
> BEGIN
> -- ERROR: syntax error at or near "$1"
> RAISE EXCEPTION $1, $2;

You probably want something like:

RAISE EXCEPTION "%: %", $1, $2;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Stefan Keller 2012-08-12 23:15:15 Re: Expression alias not recognized in WHERE clause (ERROR: relation "p" does not exist)
Previous Message Andreas Kretschmer 2012-08-12 12:40:48 Re: Deleting BLOBs