From: | Moshe Jacobson <moshe(at)neadwerx(dot)com> |
---|---|
To: | pgsql-general <pgsql-general(at)postgresql(dot)org>, Stephen Dolan <stephen(at)neadwerx(dot)com> |
Subject: | Strange behavior of "=" as assignment operator |
Date: | 2013-05-28 19:53:15 |
Message-ID: | CAJ4CxLkBFNAAsWdz=CsDkU1nC0De60WO15de=aUf6Q1W9DSj7w@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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(at)neadwerx(dot)com | www.neadwerx.com
"Quality is not an act, it is a habit." -- Aristotle
From | Date | Subject | |
---|---|---|---|
Next Message | Stephen Frost | 2013-05-28 20:06:39 | Re: Strange behavior of "=" as assignment operator |
Previous Message | Ben Chobot | 2013-05-28 17:35:50 | Re: 2 postgresql server on the same station : conflict? |