Search Postgresql Archives

Strange behavior of "=" as assignment operator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
moshe@xxxxxxxxxxxx | 
www.neadwerx.com

"Quality is not an act, it is a habit." -- Aristotle

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux