2016-10-21 5 views
1

seltsame Fehler hat, von der Funktion steigend:Anhebung Ausnahme in postgresql

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; 

Die Fehler Aussage, die ich erhalten:

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 

Schätzen Sie irgendwelche Vorschläge, danke.

+2

Daumenregel: nie doppelte Anführungszeichen in SQL verwenden - dann würden Sie nicht in dieses Problem bekommen .... –

Antwort

Verwandte Themen