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 TABLE
Time: 22.600 ms
test=# CREATE OR REPLACE FUNCTION public.fn_update_modified_timestamp()
test-# RETURNS trigger
test-# LANGUAGE plpgsql
test-# AS $function$
test$# begin
test$# NEW.modified = now();
test$# return NEW;
test$# end;
test$# $function$;
CREATE FUNCTION
Time: 10.429 ms
test=# insert into foo (some_value) values (5);
INSERT 0 1
Time: 1.979 ms
test=# create trigger tr_foo BEFORE UPDATE ON foo FOR EACH ROW EXECUTE
PROCEDURE fn_update_modified_timestamp();
CREATE TRIGGER
test=# 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 1
test=# 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
2323 Cumberland Parkway, Suite 201 | Atlanta, GA 30339
[email protected] | www.neadwerx.com
"Quality is not an act, it is a habit." -- Aristotle