Re: CURRENT_TIMESTAMP vs actual time - Mailing list pgsql-general

From John DeSoi
Subject Re: CURRENT_TIMESTAMP vs actual time
Date
Msg-id 4E5BE316-B1F5-11D9-B690-000A95B03262@pgedit.com
Whole thread Raw
In response to CURRENT_TIMESTAMP vs actual time  ("Christopher J. Bottaro" <cjbottaro@alumni.cs.utexas.edu>)
List pgsql-general
On Apr 20, 2005, at 6:15 PM, Christopher J. Bottaro wrote:

> I understand that CURRENT_TIMESTAMP marks the beginning of the current
> transaction.  I want it to be the actual time.  How do I do this?
> timeofday() returns a string, how do I convert that into a TIMESTAMP?


timeofday()::timestamp;


> Is it possible to create a column with DEFAULT value evaluated to the
> actual
> current time (i.e. not the CURRENT_TIMESTAMP which is the beginning of
> the
> current transaction).

Sure. Use the expression above or create a function for it:


create or replace function timeofday_stamp() returns timestamp as
    'select timeofday()::timestamp;'
language sql volatile;

create table test_stamp  (
    id integer primary key,
    my_stamp timestamp default timeofday_stamp()
);

insert into test_stamp values (1);
insert into test_stamp values (2);

select * from test_stamp;
  id |          my_stamp
----+----------------------------
   1 | 2005-04-20 19:35:59.884837
   2 | 2005-04-20 19:36:13.719402
(2 rows)




John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL


pgsql-general by date:

Previous
From: "Christopher J. Bottaro"
Date:
Subject: CURRENT_TIMESTAMP vs actual time
Next
From: "Jeffrey W. Baker"
Date:
Subject: Baffling sequential scan plan when index scan would be best