Is it possible to create your own error in sql, in particular on postgre and return it upon request

    2 answers 2

    For this there is a RAISE statement.

    • And I make the call through a function, can not I call it in the request right away? select raise notice 'blabla'; - Ghost
    • SELECT why? Just write like this: RAISE NOTICE 'blabla'; - Maybe it will work ... - Akina
    • ERROR: syntax error at or near "RAISE" LINE 1: RAISE NOTICE 'blabla'; - Ghost
    • also wrong - select case when 1=1 then RAISE EXCEPTION 'k;sdjk;lsajdhf;kljasdh' end ERROR: syntax error at or near "EXCEPTION" LINE 3: RAISE EXCEPTION 'k; sdjk; lsajdhf; kljasdh' - Ghost
    • Well, it is not intended RAISE for such use ... - Akina

    Good day.

    Try using RAISE EXCEPTION as indicated in the documentation, and not in the way you quote:

     RAISE EXCEPTION 'Nonexistent ID --> %', user_id USING HINT = 'Please check your user ID';