Dear PostgreSQL gurus,
It seems that the comparison operator "=" is functioning as the assignment operator ":=" in this plpgsql trigger script I wrote. I was under the impression that "=" is only for comparison and not assignment. If this is true, please explain the transcript below. If it's not true, where is this documented? I'm using PostgreSQL 9.1.4.
--test=# create table foo ( modified timestamp not null default now(), some_value integer );CREATE TABLETime: 22.600 mstest=# CREATE OR REPLACE FUNCTION public.fn_update_modified_timestamp()test-# RETURNS triggertest-# LANGUAGE plpgsqltest-# AS $function$test$# begintest$# NEW.modified = now();
test$# return NEW;test$# end;test$# $function$;CREATE FUNCTIONTime: 10.429 mstest=# insert into foo (some_value) values (5);INSERT 0 1Time: 1.979 mstest=# create trigger tr_foo BEFORE UPDATE ON foo FOR EACH ROW EXECUTE PROCEDURE fn_update_modified_timestamp();CREATE TRIGGERtest=# select modified, some_value from foo;modified | some_value----------------------------+------------2013-05-28 15:41:33.338463 | 5(1 row)test=# update foo set some_value = 6 where some_value = 5;UPDATE 1test=# select modified, some_value from foo;modified | some_value----------------------------+------------2013-05-28 15:44:51.082989 | 6(1 row)
Moshe Jacobson
Nead Werx, Inc. | Manager of Systems Engineering
Nead Werx, Inc. | Manager of Systems Engineering
2323 Cumberland Parkway, Suite 201 | Atlanta, GA 30339
moshe@xxxxxxxxxxxx | www.neadwerx.com
moshe@xxxxxxxxxxxx | www.neadwerx.com
"Quality is not an act, it is a habit." -- Aristotle