Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e14a9de

Browse files
committed
Document timeofday(), mention start-of-transaction vs. current-time
semantics, a few other small improvements.
1 parent 4dba681 commit e14a9de

File tree

1 file changed

+57
-10
lines changed

1 file changed

+57
-10
lines changed

doc/src/sgml/func.sgml

+57-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.53 2001/02/19 00:01:18 tgl Exp $ -->
1+
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.54 2001/02/21 23:15:24 tgl Exp $ -->
22

33
<chapter id="functions">
44
<title>Functions and Operators</title>
@@ -2197,6 +2197,17 @@ reasonable at all for that matter.
21972197
<entry></entry>
21982198
</row>
21992199

2200+
<row>
2201+
<entry>timeofday()</entry>
2202+
<entry>text</entry>
2203+
<entry>
2204+
returns high-precision date and time; see also <link
2205+
linkend="functions-datetime-current">below</link>
2206+
</entry>
2207+
<entry>timeofday()</entry>
2208+
<entry>Wed Feb 21 17:01:13.000126 2001 EST</entry>
2209+
</row>
2210+
22002211
<row>
22012212
<entry>timestamp(date)</entry>
22022213
<entry>timestamp</entry>
@@ -2627,7 +2638,8 @@ SELECT date_trunc('year', TIMESTAMP '2001-02-16 20:38:40');
26272638
<title>Current Date/Time</title>
26282639

26292640
<para>
2630-
The following functions are available to select the current date and/or time:
2641+
The following functions are available to obtain the current date and/or
2642+
time:
26312643
<synopsis>
26322644
CURRENT_TIME
26332645
CURRENT_DATE
@@ -2641,23 +2653,56 @@ CURRENT_TIMESTAMP
26412653
<informalexample>
26422654
<screen>
26432655
SELECT CURRENT_TIME;
2644-
<computeroutput>19:07:13</computeroutput>
2656+
<computeroutput>19:07:32</computeroutput>
26452657

26462658
SELECT CURRENT_DATE;
26472659
<computeroutput>2001-02-17</computeroutput>
26482660

26492661
SELECT CURRENT_TIMESTAMP;
2650-
<computeroutput>2001-02-17 19:07:32+00</computeroutput>
2662+
<computeroutput>2001-02-17 19:07:32-05</computeroutput>
26512663
</screen>
26522664
</informalexample>
26532665

26542666
<para>
26552667
The function <function>now()</function> is the traditional
26562668
<productname>Postgres</productname> equivalent to
26572669
<function>CURRENT_TIMESTAMP</function>.
2658-
<productname>Postgres</productname> furthermore has special
2659-
date/time <quote>constants</quote> that can be used to specify the
2660-
current time. The following three all return the same result:
2670+
</para>
2671+
2672+
<para>
2673+
There is also <function>timeofday()</function>, which returns current
2674+
time to higher precision than the <function>CURRENT_TIMESTAMP</function>
2675+
family does:
2676+
</para>
2677+
2678+
<informalexample>
2679+
<screen>
2680+
SELECT timeofday();
2681+
Sat Feb 17 19:07:32.000126 2001 EST
2682+
</screen>
2683+
</informalexample>
2684+
2685+
<para>
2686+
<function>timeofday()</function> uses the operating system call
2687+
<function>gettimeofday(2)</function>, which may have resolution as
2688+
good as microseconds (depending on your platform); the other functions
2689+
rely on <function>time(2)</function> which is restricted to one-second
2690+
resolution. For historical reasons, <function>timeofday()</function>
2691+
returns its result as a text string rather than a timestamp value.
2692+
</para>
2693+
2694+
<para>
2695+
It is quite important to realize that
2696+
<function>CURRENT_TIMESTAMP</function> and related functions all return
2697+
the time as of the start of the current transaction; their values do not
2698+
increment while a transaction is running. But
2699+
<function>timeofday()</function> returns the actual current time.
2700+
</para>
2701+
2702+
<para>
2703+
All the date/time datatypes also accept the special literal value
2704+
<literal>now</> to specify the current date and time. Thus,
2705+
the following three all return the same result:
26612706
<programlisting>
26622707
SELECT CURRENT_TIMESTAMP;
26632708
SELECT now();
@@ -2666,11 +2711,13 @@ SELECT TIMESTAMP 'now';
26662711
<note>
26672712
<para>
26682713
You do not want to use the third form when specifying a DEFAULT
2669-
value when creating a table. The system will immediately
2670-
evaluate the constant, thus when the default value is needed,
2714+
value while creating a table. The system will convert <literal>now</>
2715+
to a timestamp as soon as the constant is parsed, so that when
2716+
the default value is needed,
26712717
the time of the table creation would be used! The first two
26722718
forms will not be evaluated until the default value is used,
2673-
because they are function calls.
2719+
because they are function calls. Thus they will give the desired
2720+
behavior of defaulting to the time of row insertion.
26742721
</para>
26752722
</note>
26762723
</para>

0 commit comments

Comments
 (0)