Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case statements will support raise exception or not?

Tags:

postgresql

 case when $1 is null then raise exception 'Please enter $1'
      when $2 is null then raise exception 'Please enter $2' 
 end;

Is it will work please can any give me answer

like image 934
user2793872 Avatar asked Nov 25 '13 06:11

user2793872


2 Answers

Best I'm aware, it won't. The case operator is for expression branching, as in one-liner statements that returns a value. For more complicated things and raising exceptions, use if … then … end if;.

like image 125
Denis de Bernardy Avatar answered Oct 20 '22 14:10

Denis de Bernardy


You can verify on sqlfiddle.com if you like. I did, and it certainly did not work in postgres. Raise is a pl/pgsql command, not an sql command.

like image 1
Joe Love Avatar answered Oct 20 '22 16:10

Joe Love