I’ve got a table foo with a text field bar in it. On that table I’ve got an after update trigger that is basically the following:
CREATE OR REPLACE FUNCTION update_foo()
RETURNS TRIGGER
SECURITY DEFINER
AS
$_$
DECLARE
BEGIN
IF TG_OP = 'UPDATE' and NEW.bar = OLD.bar THEN
return NEW;
END IF;
/* Do some stuff */
END
$_$
LANGUAGE PLPGSQL;
Then I do something like this: Update foo set bar = bar || '';.
But it doesn’t bail when the text values are equal.
My question is why wouldn’t PostgreSQL 8.3, and specifically pl/PgSQL call them equal and bail out early?
Disclaimer: Table, field, and variable names have been changed from their original to allow for posting online.
It Would be because one of the values is a null.
and a null cannot be equal to any other value,
So you will need to add the extra criteria
Or