I have a table with column named modify
which is of type Date
. I have converted it to type TIMESTAMP WITHOUT TIME ZONE
.
This column data is updated by trigger :
CREATE OR REPLACE FUNCTION trigA()
RETURNS trigger AS
$BODY$
begin
new.modify=current_date;
return new;
end;
$BODY$
LANGUAGE plpgsql VOLATILE
which simply keep track of when someone updated the row.
the current_date
was ok for Date
but it lack time so I wanted to change it to: current_timestamp
. However according to the manual : current_timestamp
gives timestamp with time zone
.
I pass on the whole page and couldn't find what gives the current date and time for timestamp without time zone
type.
My question: How to insert the current date and time to a timestamp without time zone
field.
You should use LOCALTIMESTAMP
CREATE OR REPLACE FUNCTION trigA()
RETURNS trigger AS
$BODY$
begin
new.modify=LOCALTIMESTAMP;
return new;
end;
$BODY$
LANGUAGE plpgsql VOLATILE
The PostgreSQL manual mention:
CURRENT_TIME and CURRENT_TIMESTAMP deliver values with time zone; LOCALTIME and LOCALTIMESTAMP deliver values without time zone.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.