473,583 Members | 3,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2699
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_timestam p BEFORE INSERT ON table
FOR EACH ROW EXECUTE PROCEDURE set_timestamp() ;
CREATE TRIGGER update_timestam p 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*******@postg resql.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 YourEmailAddres sHere" to ma*******@postg resql.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
2973
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 the form 2005-07-13-23:45:32.000000 ....whereas the MySQL timestamp type is of the form 2005-07-13 23:45:32
2
21169
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. I'm getting weird results that I don't understand. When I use TO_DATE it changes the year, month, etc. Any ideas?
4
1443
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 in a situation where I need to do diff from the select outputs of two databases - one in 7.2.2 and one in 7.4.2.
2
3032
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 dates formatted like this: 2004-04-15 18:04:26 PM It's a bit strange, I know, but I didn't create the file. My idea of Postgres's proper...
2
4340
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 showing what I am experiencing. The last own shows how converting timestamps to dates and then ordering doesn't give you the order you want. Maybe you...
6
6299
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. Consider for the following query: - 'number' is an integer - 'procedures' is the table name - 'date' is a timestamp
3
14886
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 max(timestamp(date,time)); How to do this in postgres?
7
12939
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 the timestamp for my .xml file. Let say I query the database and then store the values in variables. I then print the variables to an .xml file. ...
3
4108
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
7895
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7826
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7935
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8193
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6579
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3818
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3843
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1433
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.