Strange behavior of "=" as assignment operator
От | Moshe Jacobson |
---|---|
Тема | Strange behavior of "=" as assignment operator |
Дата | |
Msg-id | CAJ4CxLkBFNAAsWdz=CsDkU1nC0De60WO15de=aUf6Q1W9DSj7w@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: Strange behavior of "=" as assignment operator
|
Список | 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 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@neadwerx.com | www.neadwerx.com
moshe@neadwerx.com | www.neadwerx.com
"Quality is not an act, it is a habit." -- Aristotle
В списке pgsql-general по дате отправления: