在 PostgreSQL 中引发异常

3

遇到一个奇怪的错误,来自函数:

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;

我收到的错误提示信息是:
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

感谢任何建议,谢谢。

3
经验之谈:在SQL中永远不要使用双引号——这样就不会遇到这个问题了。 - user330315
1个回答

11

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接