giozh
giozh

Reputation: 10068

verify a boolean condition inside a function

I have written a PostgreSQL function containing a while statement like:

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

Where id_exist is a boolean variable initialized by calling check_if_exist() method (used also inside while code) that returned a boolean value.

Now when I try to call my function, I get this error

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

Upvotes: 0

Views: 64

Answers (1)

Curt
Curt

Reputation: 5722

The comparison operator is a single equals sign ("=", not "==")

Also, did you set a value to id_exist before you entered the loop?

Upvotes: 1

Related Questions