Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR: operator does not exist: integer == integer

Tags:

sql

postgresql

I am using these statements in a postgres function.

Select count(*) into V_check
from employee
where employee_name like 'Raj%';

if V_check == 0
then
     update exception set exception_found = 'Raj';
end if;

I get this error :

ERROR:  operator does not exist: integer == integer
LINE 1: SELECT V_check == 0
like image 532
Rajeev A Nair Avatar asked Nov 06 '17 01:11

Rajeev A Nair


2 Answers

You should use = instead of ==.

Here is a list of the different comparison operators that you can use:

Operator    Description
=   Equal
<>  Not equal. Note: In some versions of SQL this operator may be written as !=
>   Greater than
<   Less than
>=  Greater than or equal
<=  Less than or equal
BETWEEN Between an inclusive range
LIKE    Search for a pattern
IN  To specify multiple possible values for a column
like image 137
Allan Avatar answered Nov 16 '22 12:11

Allan


As pointed out, the comparison operator for equality is = not ==. However, you should write the condition as:

if not exists (select 1 from employee where employee_name like 'Raj%')
then
     update exception
         set exception_found = 'Raj';
end if;

This saves you a declaration. Also, not exists is faster than count(*) -- because not exists can stop at the first matching row.

Or dispense with the conditional entirely:

update exception 
    set exception_found = 'Raj'
    where not exists (select 1 from employee where employee_name like 'Raj%');
like image 22
Gordon Linoff Avatar answered Nov 16 '22 14:11

Gordon Linoff