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 $ -->
2
2
3
3
<chapter id="functions">
4
4
<title>Functions and Operators</title>
@@ -5302,6 +5302,15 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
5302
5302
<indexterm>
5303
5303
<primary>now</primary>
5304
5304
</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>
5305
5314
<indexterm>
5306
5315
<primary>timeofday</primary>
5307
5316
</indexterm>
@@ -5358,7 +5367,7 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
5358
5367
<row>
5359
5368
<entry><literal><function>current_timestamp</function></literal></entry>
5360
5369
<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">
5362
5371
</entry>
5363
5372
<entry></entry>
5364
5373
<entry></entry>
@@ -5474,8 +5483,36 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
5474
5483
<row>
5475
5484
<entry><literal><function>now</function>()</literal></entry>
5476
5485
<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">
5479
5516
</entry>
5480
5517
<entry></entry>
5481
5518
<entry></entry>
@@ -5484,7 +5521,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
5484
5521
<row>
5485
5522
<entry><literal><function>timeofday</function>()</literal></entry>
5486
5523
<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">
5488
5526
</entry>
5489
5527
<entry></entry>
5490
5528
<entry></entry>
@@ -6072,7 +6110,7 @@ SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'MST';
6072
6110
</sect2>
6073
6111
6074
6112
<sect2 id="functions-datetime-current">
6075
- <title>Current Date/Time</title>
6113
+ <title>Date/Time of Transaction Start </title>
6076
6114
6077
6115
<indexterm>
6078
6116
<primary>date</primary>
@@ -6085,8 +6123,8 @@ SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'MST';
6085
6123
</indexterm>
6086
6124
6087
6125
<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 :
6090
6128
<synopsis>
6091
6129
CURRENT_DATE
6092
6130
CURRENT_TIME
@@ -6138,12 +6176,6 @@ SELECT LOCALTIMESTAMP;
6138
6176
</screen>
6139
6177
</para>
6140
6178
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
-
6147
6179
<para>
6148
6180
It is important to know that
6149
6181
<function>CURRENT_TIMESTAMP</function> and related functions return
@@ -6152,26 +6184,31 @@ SELECT LOCALTIMESTAMP;
6152
6184
the intent is to allow a single transaction to have a consistent
6153
6185
notion of the <quote>current</quote> time, so that multiple
6154
6186
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.
6156
6190
</para>
6157
6191
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>
6164
6201
6165
6202
<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.
6175
6212
</para>
6176
6213
6177
6214
<para>
0 commit comments