Skip site navigation (1) Skip section navigation (2)

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

From: "Andrus" <kobruleht2(at)hot(dot)ee>
To: <pgsql-general(at)postgresql(dot)org>
Subject: How to raise error from PostgreSql SQL statement if some condition is met
Date: 2012-08-11 19:07:25
Message-ID: 9E0A5B8931B849A4844AE348C4A0CC34@dell2 (view raw or flat)
Thread:
Lists: pgsql-general
I’m looking for a way to raise error from sql select if some condition is met.
Tried code below to got error shown in comment.
How to fix ?

Andrus

    CREATE OR REPLACE FUNCTION "exec"(text)
      RETURNS text AS
    $BODY$ 
        BEGIN 
          EXECUTE $1; 
          RETURN $1; 
        END; 
    $BODY$
      LANGUAGE plpgsql VOLATILE;
      
    -- ERROR:  syntax error at or near "raise"
    -- LINE 1: raise 'test' 
    
    select exec('raise ''test'' ') where true -- in real application true is replaced by some condition 

Responses

pgsql-general by date

Next:From: Pavel StehuleDate: 2012-08-11 20:46:33
Subject: Re: How to raise error from PostgreSql SQL statement if some condition is met
Previous:From: Dan HalbertDate: 2012-08-11 19:01:16
Subject: Re: select distinct in a subquery bug/problem

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group