Raising exception in postgresql

postgresql

Solution

You should not use `"` for stating the exception text. Use `'` instead.

See https://www.postgresql.org/docs/9.3/static/plpgsql-errors-and-messages.html

Problem

Having strange error, rising from function: ``` CREATE OR REPLACE FUNCTION addAnswer(bodyR VARCHAR, userIdR BIGINT, qId BIGINT) RETURNS BIGINT AS $$ DECLARE ret BIGINT; author_idR BIGINT; BEGIN author_idR := (SELECT "a"."author_id" FROM "question" "a" WHERE "a"."id"=qId); IF (author_idR = userIdR ) THEN RAISE EXCEPTION "Question author and answer author shouldn't match!"; ENDIF; INSERT INTO "answer"("body", "author_id", "created_at", "question_id") VALUES (bodyR, userIdR, CURRENT_TIMESTAMP, qId); ret := LASTVAL(); RETURN ret; END $$ LANGUAGE plpgsql; ``` The error statement I receive: ``` ERROR: unrecognized exception condition "Question author and answer author shouldn't match!" CONTEXT: compilation of PL/pgSQL function "addanswer" near line 9 ********** Error ********** ERROR: unrecognized exception condition "Question author and answer author shouldn't match!" SQL state: 42704 Context: compilation of PL/pgSQL function "addanswer" near line 9 ``` Appreciate any suggestions, thanks.

Original source