1- <!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.314 2006/04/23 03:39:50 momjian Exp $ -->
1+ <!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.315 2006/04/25 00:25:15 momjian Exp $ -->
22
33 <chapter id="functions">
44 <title>Functions and Operators</title>
@@ -5302,6 +5302,15 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
53025302 <indexterm>
53035303 <primary>now</primary>
53045304 </indexterm>
5305+ <indexterm>
5306+ <primary>transaction_timestamp</primary>
5307+ </indexterm>
5308+ <indexterm>
5309+ <primary>statement_timestamp</primary>
5310+ </indexterm>
5311+ <indexterm>
5312+ <primary>clock_timestamp</primary>
5313+ </indexterm>
53055314 <indexterm>
53065315 <primary>timeofday</primary>
53075316 </indexterm>
@@ -5358,7 +5367,7 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
53585367 <row>
53595368 <entry><literal><function>current_timestamp</function></literal></entry>
53605369 <entry><type>timestamp with time zone</type></entry>
5361- <entry>Date and time; see <xref linkend="functions-datetime-current">
5370+ <entry>Date and time of start of current transaction ; see <xref linkend="functions-datetime-current">
53625371 </entry>
53635372 <entry></entry>
53645373 <entry></entry>
@@ -5474,8 +5483,36 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
54745483 <row>
54755484 <entry><literal><function>now</function>()</literal></entry>
54765485 <entry><type>timestamp with time zone</type></entry>
5477- <entry>Current date and time (equivalent to
5478- <function>current_timestamp</function>); see <xref linkend="functions-datetime-current">
5486+ <entry>Date and time of start of current transaction (equivalent to
5487+ <function>CURRENT_TIMESTAMP</function>); see <xref linkend="functions-datetime-current">
5488+ </entry>
5489+ <entry></entry>
5490+ <entry></entry>
5491+ </row>
5492+
5493+ <row>
5494+ <entry><literal><function>transaction_timestamp</function>()</literal></entry>
5495+ <entry><type>timestamp with time zone</type></entry>
5496+ <entry>Date and time of start of current transaction (equivalent to
5497+ <function>CURRENT_TIMESTAMP</function>); see <xref linkend="functions-datetime-current">
5498+ </entry>
5499+ <entry></entry>
5500+ <entry></entry>
5501+ </row>
5502+
5503+ <row>
5504+ <entry><literal><function>statement_timestamp</function>()</literal></entry>
5505+ <entry><type>timestamp with time zone</type></entry>
5506+ <entry>Date and time of start of current statement; see <xref linkend="functions-datetime-current">
5507+ </entry>
5508+ <entry></entry>
5509+ <entry></entry>
5510+ </row>
5511+
5512+ <row>
5513+ <entry><literal><function>clock_timestamp</function>()</literal></entry>
5514+ <entry><type>timestamp with time zone</type></entry>
5515+ <entry>Current date and time (changes during statement execution); see <xref linkend="functions-datetime-current">
54795516 </entry>
54805517 <entry></entry>
54815518 <entry></entry>
@@ -5484,7 +5521,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
54845521 <row>
54855522 <entry><literal><function>timeofday</function>()</literal></entry>
54865523 <entry><type>text</type></entry>
5487- <entry>Current date and time; see <xref linkend="functions-datetime-current">
5524+ <entry>Current date and time (like <function>clock_timestamp</>), but as a Unix-style <type>text</> value;
5525+ see <xref linkend="functions-datetime-current">
54885526 </entry>
54895527 <entry></entry>
54905528 <entry></entry>
@@ -6072,7 +6110,7 @@ SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'MST';
60726110 </sect2>
60736111
60746112 <sect2 id="functions-datetime-current">
6075- <title>Current Date/Time</title>
6113+ <title>Date/Time of Transaction Start </title>
60766114
60776115 <indexterm>
60786116 <primary>date</primary>
@@ -6085,8 +6123,8 @@ SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'MST';
60856123 </indexterm>
60866124
60876125 <para>
6088- The following functions are available to obtain the current date and/or
6089- time:
6126+ The following functions are available to obtain the date and/or
6127+ time of the start of the current transaction :
60906128<synopsis>
60916129CURRENT_DATE
60926130CURRENT_TIME
@@ -6138,12 +6176,6 @@ SELECT LOCALTIMESTAMP;
61386176</screen>
61396177 </para>
61406178
6141- <para>
6142- The function <function>now()</function> is the traditional
6143- <productname>PostgreSQL</productname> equivalent to
6144- <function>CURRENT_TIMESTAMP</function>.
6145- </para>
6146-
61476179 <para>
61486180 It is important to know that
61496181 <function>CURRENT_TIMESTAMP</function> and related functions return
@@ -6152,26 +6184,31 @@ SELECT LOCALTIMESTAMP;
61526184 the intent is to allow a single transaction to have a consistent
61536185 notion of the <quote>current</quote> time, so that multiple
61546186 modifications within the same transaction bear the same
6155- time stamp.
6187+ time stamp. Consider using <function>statement_timestamp</> or
6188+ <function>clock_timestamp</> if you need something that changes
6189+ more frequently.
61566190 </para>
61576191
6158- <note>
6159- <para>
6160- Other database systems may advance these values more
6161- frequently.
6162- </para>
6163- </note>
6192+ <para>
6193+ <function>CURRENT_TIMESTAMP</> might not be the
6194+ transaction start time on other database systems.
6195+ For this reason, and for completeness,
6196+ <function>transaction_timestamp</> is provided.
6197+ The function <function>now()</function> is the traditional
6198+ <productname>PostgreSQL</productname> equivalent to
6199+ the SQL-standard <function>CURRENT_TIMESTAMP</function>.
6200+ </para>
61646201
61656202 <para>
6166- There is also the function <function>timeofday()</function> which
6167- returns the wall-clock time and advances during transactions. For
6168- historical reasons <function>timeofday()</function> returns a
6169- <type>text</type> string rather than a <type>timestamp</type>
6170- value:
6171- <screen>
6172- SELECT timeofday();
6173- <lineannotation>Result: </lineannotation><computeroutput>Sat Feb 17 19:07:32.000126 2001 EST</computeroutput>
6174- </screen>
6203+ <function>STATEMENT_TIMESTAMP</> is the time the statement
6204+ arrived at the server from the client. It is not the time
6205+ the command started execution. If multiple commands were
6206+ sent as a single query string to the server, each command
6207+ has the same <function>STATEMENT_TIMESTAMP</> because they
6208+ all arrived at the same time. Also, commands executed
6209+ by server-side functions have a <function>STATEMENT_TIMESTAMP</>
6210+ based on the time the client sent the query that triggered
6211+ the function, not the time the function was executed.
61756212 </para>
61766213
61776214 <para>
0 commit comments