【问题标题】:verify a boolean condition inside a function验证函数内的布尔条件
【发布时间】:2013-07-07 10:29:25
【问题描述】:

我编写了一个 PostgreSQL 函数,其中包含如下的 while 语句:

WHILE id_exist == 'f' LOOP
    lotto_id = lotto_id + 1;
    id_exist = check_if_exist(lotto_id, 'lotto', 'id');
END LOOP;

其中id_exist 是一个布尔变量,通过调用返回布尔值的check_if_exist() 方法(也在while 代码中使用)初始化。

现在当我尝试调用我的函数时,我得到了这个错误

ERROR:  operator does not exist: boolean == unknown
LINE 1: SELECT id_exist == 'f'
                    ^
HINT:  No operator matches the given name and argument type(s). You might need to add
explicit type casts.
QUERY:  SELECT id_exist == 'f'
CONTEXT:  PL/pgSQL function "acquistolotto" line 11 at WHILE

【问题讨论】:

    标签: sql function postgresql stored-procedures


    【解决方案1】:

    比较运算符是一个等号(“=”,而不是“==”)

    另外,您是否在进入循环之前为 id_exist 设置了值?

    【讨论】:

    • 好的,没错。但现在我有一个无限循环问题。我会打开另一个问题。谢谢 当然,我已经设置了调用 check_if_exist() 函数的值
    • 如果是这种情况,您的 check_if_exist() 函数似乎总是返回“false”。先看看那个。
    猜你喜欢
    • 2016-09-19
    • 2021-05-15
    • 2016-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-06
    • 2021-12-06
    相关资源
    最近更新 更多