473,385 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

the behaviour of timestamp on postgres.

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.

How is the behaviour of the timestamp on postgres? I
have define the datatype of the column with
"timestamp" but each time I inserted a new record into
the table than the timestamp column (with datatype
"timestamp") stays empty.

How can I make the postgres complete the value of the
timestamp field automatically?

Please let me know.

Thank you very much in advance.

__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #1
5 2675
Prabu Subroto <pr***********@yahoo.com> writes:
How can I make the postgres complete the value of the
timestamp field automatically?


Add a DEFAULT NOW() clause to the column definition.

-Doug
--
Let us cross over the river, and rest under the shade of the trees.
--T. J. Jackson, 1863

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #2
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

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #3
It's solved.

Thank you very much, Doug.

Thanks.
--- Doug McNaught <do**@mcnaught.org> wrote:
Prabu Subroto <pr***********@yahoo.com> writes:
How can I make the postgres complete the value of

the
timestamp field automatically?


Add a DEFAULT NOW() clause to the column definition.
-Doug
--
Let us cross over the river, and rest under the
shade of the trees.
--T. J. Jackson, 1863



__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #4
Prabu,

Be aware that this will only work for inserts, and updating the row will
not automatically update the timestamp column. You will have to do it
yourself if you need that, either by using the right query (which is
actually a preferred solution).
Automatically you could do it through a rule - but I have never used the
Postgres rule system, so I don't know how to do that.
The update trigger posted in another reply will also work.

HTH,
Csaba.

On Wed, 2004-08-11 at 16:47, Prabu Subroto wrote:
It's solved.

Thank you very much, Doug.

Thanks.
--- Doug McNaught <do**@mcnaught.org> wrote:
Prabu Subroto <pr***********@yahoo.com> writes:
How can I make the postgres complete the value of

the
timestamp field automatically?


Add a DEFAULT NOW() clause to the column definition.
-Doug
--
Let us cross over the river, and rest under the
shade of the trees.
--T. J. Jackson, 1863



__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #5

On Wed, 11 Aug 2004, Prabu Subroto wrote:
How is the behaviour of the timestamp on postgres? I
It's pretty much just a plain datatype.
have define the datatype of the column with
"timestamp" but each time I inserted a new record into
the table than the timestamp column (with datatype
"timestamp") stays empty.

How can I make the postgres complete the value of the
timestamp field automatically?


If you want insert time setting, you can use a default
clause on the column.

If you want update time modification, you can write a
before trigger that updates the column.

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: George Develekos | last post by:
I need to import into mysql data from DB2. One of the DB2 table columns is of the TIMESTAMP type, which, unlike its MySQL counterpart, supports fractions of a second, up to 6 digits, i.e. it is of...
2
by: Campano, Troy | last post by:
Hi, I'm trying to compare a timestamp to current_timestamp but I'm having trouble. I want to compare just the date piece of my timestamp column to just the date piece of current_timestamp. ...
4
by: Gunasekaran Balakrishnan | last post by:
Hi, I am seeing a different sorting behaviour for varchar columns in Postgres 7.4.2. postgres 7.4.2 is ignoring case for varchar columns for "ORDER BY" commands where as 7.2.2 is not. I am...
2
by: Kevin Bartz | last post by:
Hi Postgressers! I really like Postgres. Thanks for all your work on it. I just have a problem with the way it's handling my flat file's timestamp columns. I have a flat file with a column with...
2
by: Russell Smith | last post by:
Timestamps support infinity. However if appears dates do not. When timestamps are cast to dates, there is no output. Is this an acceptable option or not? Below are a number of examples...
6
by: Scott Nixon | last post by:
New to Postgres 7.3 from 7.0. Am having some trouble with a query that worked in 7.0 but not in 7.3.....can't seem to figure out the syntax or find info about how to do this anywhere. ...
3
by: krithikas | last post by:
I have a table (which i cannot modify) where date and time fields are stored as VARCHAR. But i have to cast these fields into timestamp. My requirement is like, timestamp (select date, time where...
7
by: bdbeames | last post by:
I never used Perl before, so I need a little help formating a date. What I'm doing is querying a postgres database and then creating a .xml file for a RSS feed. I don't know how to correctly format...
3
by: johnhelen | last post by:
Hello I have string of time like this 2007/09/19 18:55:14 Also i have a timestamp field in a postgres database with timezone like this 2004-10-19 10:23:54+02
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.