Thread: now() with microsecond granulity needed
Hello! using now() to init TIMESTAMP fields I got resolution of one second. How can I define DEFAULT in column (TIMESTAMP type) to get higher time-resolution (TIMESTAMP supports microseconds). Please CC the answer to me. -- radoslaw.stachowiak.........................................http://alter.pl/
Radoslaw Stachowiak <radek@alter.pl> writes: > using now() to init TIMESTAMP fields I got resolution of one second. How > can I define DEFAULT in column (TIMESTAMP type) to get higher > time-resolution (TIMESTAMP supports microseconds). You could make a variant of now() that relies on gettimeofday() instead of time(). Note that you probably won't get microsecond precision in any case... regards, tom lane
*** Tom Lane <tgl@sss.pgh.pa.us> [Tuesday, 20.February.2001, 11:57 -0500]: > > using now() to init TIMESTAMP fields I got resolution of one second. How > > can I define DEFAULT in column (TIMESTAMP type) to get higher > > time-resolution (TIMESTAMP supports microseconds). > > You could make a variant of now() that relies on gettimeofday() instead > of time(). Note that you probably won't get microsecond precision in > any case... Do You mean changing sources and recompiling? So there is no way of getting more accurate NOW time directly in SQL ? /DEFAULT clause/ at this moment? I just have now about 5..10 inserts per second, so in fact even ms would help me. -- radoslaw.stachowiak.........................................http://alter.pl/
>>>>> "Radoslaw" == Radoslaw Stachowiak <radek@alter.pl> writes: Radoslaw> *** Tom Lane <tgl@sss.pgh.pa.us> [Tuesday, Radoslaw> 20.February.2001, 11:57 -0500]: >> > using now() toinit TIMESTAMP fields I got resolution of one >> second. How > can I define DEFAULT in column (TIMESTAMP type) >> toget higher > time-resolution (TIMESTAMP supports >> microseconds). >> >> You could make a variant of now() thatrelies on gettimeofday() >> instead of time(). Note that you probably won't get >> microsecond precision in anycase... Radoslaw> Do You mean changing sources and recompiling? So there Radoslaw> is no way of getting more accurate NOW timedirectly in Radoslaw> SQL ? /DEFAULT clause/ at this moment? the timeofday function seems to work: acspg=# select timeofday(); timeofday -------------------------------------Wed Feb 21 15:56:43.150389 2001 EST (1 row) acspg=#
Daniel Wickstrom <danw@rtp.ericsson.se> writes: > the timeofday function seems to work: Hmm, exactly what I was thinking of, except that it returns a text rather than a timestamp (a strange choice...). It seems a little buggy as well because the formatting of the microseconds part is wrong --- will fix that, and document it. regards, tom lane
*** Tom Lane <tgl@sss.pgh.pa.us> [Wednesday, 21.February.2001, 16:55 -0500]: > Hmm, exactly what I was thinking of, except that it returns a text > rather than a timestamp (a strange choice...). But it's implicit casted to timestamp type so i think is good choice to use in DEFAULT clause at this moment. Correct me if I'm wrong. > It seems a little > buggy as well because the formatting of the microseconds part is > wrong --- will fix that, and document it. In 7.1 version? -- radoslaw.stachowiak.........................................http://alter.pl/