| From: | Sebastian Böck <sebastianboeck(at)freenet(dot)de> |
|---|---|
| To: | Prabu Subroto <prabu_subroto(at)yahoo(dot)com> |
| Cc: | Postgres General Milis <pgsql-general(at)postgresql(dot)org> |
| Subject: | Re: the behaviour of timestamp on postgres. |
| Date: | 2004-08-11 14:47:27 |
| Message-ID: | 411A317F.9080904@freenet.de |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Prabu Subroto wrote:
> Dear my friends...
>
> I created some tables with field timestamp (datatype
> also timestamp). I mean, I want to have the data when
> each record inserted or modified in the tables.
>
> on MysQL, I just need to define the column (field)
> with datatype "timestamp" and that's all. each time
> new record inserted than the timestamp value will be
> inserted automaticall. also for the data modification,
> each time the data in the record modified than the
> value of timestamp column will be modified
> automatically.
You can use triggers for that.
Try something like:
CREATE FUNCTION set_timestamp() RETURNS TRIGGER AS '
BEGIN
NEW.timestamp := now();
RETURN NEW;
END;
' LANGUAGE 'plpgsql';
CREATE TRIGGER insert_timestamp BEFORE INSERT ON table
FOR EACH ROW EXECUTE PROCEDURE set_timestamp();
CREATE TRIGGER update_timestamp BEFORE UPDATE ON table
FOR EACH ROW EXECUTE PROCEDURE set_timestamp();
HTH
Sebastian
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Prabu Subroto | 2004-08-11 14:47:35 | Re: the behaviour of timestamp on postgres. |
| Previous Message | Liam Lesboch | 2004-08-11 14:42:48 | Re: Replication options? |