psql IS NOT NULL返回f

时间:2014-12-07 16:52:19

标签: psql

我有一个函数,registration,它应该在某些情况下向表中添加一行。我已经收到了一段代码。如果select *返回非空表行,我想引发异常而不添加行。该示例似乎表明rowt不为null,但是rowt IS NOT NULL返回f(并且不会引发异常)。我希望这是我看不到的小事。

    select * into rowt from Email where email_email = eml;
    RAISE NOTICE '%, rowt IS NOT NULL:%',rowt, rowt IS NOT NULL;
    if rowt IS NOT NULL THEN
       RAISE EXCEPTION 'email address, %, already registered.' , eml;
    END IF;

    NOTICE:  (7,,,), rowt IS NOT NULL:f
    registration 
    --------------
        21
    (1 row)

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

您可以使用特殊变量FOUND来检查是否找到并返回了一行。

SELECT * INTO rowt FROM Email WEHERE email_email = eml;

IF FOUND THEN
   RAISE EXCEPTION 'email address, %, already registered.' , eml;
END IF;