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
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
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%');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With