We have one 2 field in of type 'timestampz' like createdon & updatedon
createdon field is inserted using 'Now()
' function of postgresql.
and i need to insert updatedon field by using php. like i try to insert using 'date( 'Y-m-d H:i:s' , $timestamp );
'.
When i try to get updated field is gives me wrong result.
I want to know i want to insert timestampz using php how i can to that.
Can't you do something like "UPDATE table SET ..., updatedon = NOW() WHERE ..."?
The following article describes how to implement the timestamp behavior of MySql with Postgres:
It works by creating a trigger:
CREATE OR REPLACE FUNCTION trg_handle_timestamp() RETURNS TRIGGER AS $BODY$
BEGIN
IF NEW.y = OLD.y THEN NEW.y := now(); END IF;
RETURN NEW;
END;
$BODY$ LANGUAGE 'plpgsql';
CREATE TRIGGER trg_handle_timestamp
BEFORE UPDATE ON test FOR EACH ROW EXECUTE PROCEDURE trg_handle_timestamp();