Reputation: 515
I'm trying to understand expections in postgresql. Maybe my problem is easy but not for me. Can someone tell me what is wrong with this query ? ERROR: syntax error at or near "EXCEPTION"
BEGIN;
select 1;
EXCEPTION
WHEN others THEN
RAISE INFO 'Caught';
END;
Upvotes: 2
Views: 2430
Reputation: 37472
If you want an anonymous block you'd have to use DO
. You can't just start a block in the middle of nowhere.
DO
$$
BEGIN
SELECT 1;
EXCEPTION WHEN others THEN
RAISE INFO 'Caught';
END;
$$
LANGUAGE PLpgSQL;
Upvotes: 3