1
- <!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.322 2006/06/18 15:38:35 petere Exp $ -->
1
+ <!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.323 2006/06/19 16:13:01 tgl Exp $ -->
2
2
3
3
<chapter id="functions">
4
4
<title>Functions and Operators</title>
@@ -5357,7 +5357,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
5357
5357
<row>
5358
5358
<entry><literal><function>current_date</function></literal></entry>
5359
5359
<entry><type>date</type></entry>
5360
- <entry>Today's date; see <xref linkend="functions-datetime-current">
5360
+ <entry>Current date;
5361
+ see <xref linkend="functions-datetime-current">
5361
5362
</entry>
5362
5363
<entry></entry>
5363
5364
<entry></entry>
@@ -5366,7 +5367,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
5366
5367
<row>
5367
5368
<entry><literal><function>current_time</function></literal></entry>
5368
5369
<entry><type>time with time zone</type></entry>
5369
- <entry>Time of day; see <xref linkend="functions-datetime-current">
5370
+ <entry>Current time of day;
5371
+ see <xref linkend="functions-datetime-current">
5370
5372
</entry>
5371
5373
<entry></entry>
5372
5374
<entry></entry>
@@ -5375,7 +5377,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
5375
5377
<row>
5376
5378
<entry><literal><function>current_timestamp</function></literal></entry>
5377
5379
<entry><type>timestamp with time zone</type></entry>
5378
- <entry>Date and time of start of current transaction; see <xref linkend="functions-datetime-current">
5380
+ <entry>Current date and time (start of current transaction);
5381
+ see <xref linkend="functions-datetime-current">
5379
5382
</entry>
5380
5383
<entry></entry>
5381
5384
<entry></entry>
@@ -5384,8 +5387,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
5384
5387
<row>
5385
5388
<entry><literal><function>date_part</function>(<type>text</type>, <type>timestamp</type>)</literal></entry>
5386
5389
<entry><type>double precision</type></entry>
5387
- <entry>Get subfield (equivalent to
5388
- <function>extract</function>); see <xref linkend="functions-datetime-extract">
5390
+ <entry>Get subfield (equivalent to <function>extract</function>);
5391
+ see <xref linkend="functions-datetime-extract">
5389
5392
</entry>
5390
5393
<entry><literal>date_part('hour', timestamp '2001-02-16 20:38:40')</literal></entry>
5391
5394
<entry><literal>20</literal></entry>
@@ -5473,7 +5476,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
5473
5476
<row>
5474
5477
<entry><literal><function>localtime</function></literal></entry>
5475
5478
<entry><type>time</type></entry>
5476
- <entry>Time of day; see <xref linkend="functions-datetime-current">
5479
+ <entry>Current time of day;
5480
+ see <xref linkend="functions-datetime-current">
5477
5481
</entry>
5478
5482
<entry></entry>
5479
5483
<entry></entry>
@@ -5482,7 +5486,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
5482
5486
<row>
5483
5487
<entry><literal><function>localtimestamp</function></literal></entry>
5484
5488
<entry><type>timestamp</type></entry>
5485
- <entry>Date and time; see <xref linkend="functions-datetime-current">
5489
+ <entry>Current date and time (start of current transaction);
5490
+ see <xref linkend="functions-datetime-current">
5486
5491
</entry>
5487
5492
<entry></entry>
5488
5493
<entry></entry>
@@ -5491,8 +5496,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
5491
5496
<row>
5492
5497
<entry><literal><function>now</function>()</literal></entry>
5493
5498
<entry><type>timestamp with time zone</type></entry>
5494
- <entry>Date and time of start of current transaction (equivalent to
5495
- <function>CURRENT_TIMESTAMP</function>); see <xref linkend="functions-datetime-current">
5499
+ <entry>Current date and time ( start of current transaction);
5500
+ see <xref linkend="functions-datetime-current">
5496
5501
</entry>
5497
5502
<entry></entry>
5498
5503
<entry></entry>
@@ -5501,8 +5506,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
5501
5506
<row>
5502
5507
<entry><literal><function>transaction_timestamp</function>()</literal></entry>
5503
5508
<entry><type>timestamp with time zone</type></entry>
5504
- <entry>Date and time of start of current transaction (equivalent to
5505
- <function>CURRENT_TIMESTAMP</function>); see <xref linkend="functions-datetime-current">
5509
+ <entry>Current date and time ( start of current transaction);
5510
+ see <xref linkend="functions-datetime-current">
5506
5511
</entry>
5507
5512
<entry></entry>
5508
5513
<entry></entry>
@@ -5511,7 +5516,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
5511
5516
<row>
5512
5517
<entry><literal><function>statement_timestamp</function>()</literal></entry>
5513
5518
<entry><type>timestamp with time zone</type></entry>
5514
- <entry>Date and time of start of current statement; see <xref linkend="functions-datetime-current">
5519
+ <entry>Current date and time (start of current statement);
5520
+ see <xref linkend="functions-datetime-current">
5515
5521
</entry>
5516
5522
<entry></entry>
5517
5523
<entry></entry>
@@ -5520,7 +5526,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
5520
5526
<row>
5521
5527
<entry><literal><function>clock_timestamp</function>()</literal></entry>
5522
5528
<entry><type>timestamp with time zone</type></entry>
5523
- <entry>Current date and time (changes during statement execution); see <xref linkend="functions-datetime-current">
5529
+ <entry>Current date and time (changes during statement execution);
5530
+ see <xref linkend="functions-datetime-current">
5524
5531
</entry>
5525
5532
<entry></entry>
5526
5533
<entry></entry>
@@ -5529,8 +5536,9 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
5529
5536
<row>
5530
5537
<entry><literal><function>timeofday</function>()</literal></entry>
5531
5538
<entry><type>text</type></entry>
5532
- <entry>Current date and time (like <function>clock_timestamp</>), but as a Unix-style <type>text</> value;
5533
- see <xref linkend="functions-datetime-current">
5539
+ <entry>Current date and time
5540
+ (like <function>clock_timestamp</>, but as a <type>text</> string);
5541
+ see <xref linkend="functions-datetime-current">
5534
5542
</entry>
5535
5543
<entry></entry>
5536
5544
<entry></entry>
@@ -6118,7 +6126,7 @@ SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'MST';
6118
6126
</sect2>
6119
6127
6120
6128
<sect2 id="functions-datetime-current">
6121
- <title>Date/Time of Transaction Start </title>
6129
+ <title>Current Date/Time</title>
6122
6130
6123
6131
<indexterm>
6124
6132
<primary>date</primary>
@@ -6131,8 +6139,10 @@ SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'MST';
6131
6139
</indexterm>
6132
6140
6133
6141
<para>
6134
- The following functions are available to obtain the date and/or
6135
- time of the start of the current transaction:
6142
+ <productname>PostgreSQL</productname> provides a number of functions
6143
+ that return values related to the current date and time. These
6144
+ SQL-standard functions all return values based on the start time of
6145
+ the current transaction:
6136
6146
<synopsis>
6137
6147
CURRENT_DATE
6138
6148
CURRENT_TIME
@@ -6185,43 +6195,61 @@ SELECT LOCALTIMESTAMP;
6185
6195
</para>
6186
6196
6187
6197
<para>
6188
- It is important to know that
6189
- <function>CURRENT_TIMESTAMP</function> and related functions return
6190
- the start time of the current transaction; their values do not
6198
+ Since these functions return
6199
+ the start time of the current transaction, their values do not
6191
6200
change during the transaction. This is considered a feature:
6192
6201
the intent is to allow a single transaction to have a consistent
6193
6202
notion of the <quote>current</quote> time, so that multiple
6194
6203
modifications within the same transaction bear the same
6195
- time stamp. Consider using <function>statement_timestamp</> or
6196
- <function>clock_timestamp</> if you need something that changes
6197
- more frequently.
6204
+ time stamp.
6198
6205
</para>
6199
6206
6207
+ <note>
6208
+ <para>
6209
+ Other database systems may advance these values more
6210
+ frequently.
6211
+ </para>
6212
+ </note>
6213
+
6200
6214
<para>
6201
- <function>CURRENT_TIMESTAMP</> might not be the
6202
- transaction start time on other database systems.
6203
- For this reason, and for completeness,
6204
- <function>transaction_timestamp</> is provided.
6205
- The function <function>now()</function> is the traditional
6206
- <productname>PostgreSQL</productname> equivalent to
6207
- the SQL-standard <function>CURRENT_TIMESTAMP</function>.
6215
+ <productname>PostgreSQL</productname> also provides functions that
6216
+ return the start time of the current statement, as well as the actual
6217
+ current time at the instant the function is called. The complete list
6218
+ of non-SQL-standard time functions is:
6219
+ <synopsis>
6220
+ now()
6221
+ transaction_timestamp()
6222
+ statement_timestamp()
6223
+ clock_timestamp()
6224
+ timeofday()
6225
+ </synopsis>
6208
6226
</para>
6209
6227
6210
6228
<para>
6211
- <function>STATEMENT_TIMESTAMP</> is the time the statement
6212
- arrived at the server from the client. It is not the time
6213
- the command started execution. If multiple commands were
6214
- sent as a single query string to the server, each command
6215
- has the same <function>STATEMENT_TIMESTAMP</> because they
6216
- all arrived at the same time. Also, commands executed
6217
- by server-side functions have a <function>STATEMENT_TIMESTAMP</>
6218
- based on the time the client sent the query that triggered
6219
- the function, not the time the function was executed.
6229
+ <function>now()</> is a traditional <productname>PostgreSQL</productname>
6230
+ equivalent to <function>CURRENT_TIMESTAMP</function>.
6231
+ <function>transaction_timestamp()</> is likewise equivalent to
6232
+ <function>CURRENT_TIMESTAMP</function>, but is named to clearly reflect
6233
+ what it returns.
6234
+ <function>statement_timestamp()</> returns the start time of the current
6235
+ statement (more specifically, the time of receipt of the latest command
6236
+ message from the client).
6237
+ <function>statement_timestamp()</> and <function>transaction_timestamp()</>
6238
+ return the same value during the first command of a transaction, but may
6239
+ differ during subsequent commands.
6240
+ <function>clock_timestamp()</> returns the actual current time, and
6241
+ therefore its value changes even within a single SQL command.
6242
+ <function>timeofday()</> is a historical
6243
+ <productname>PostgreSQL</productname> function. Like
6244
+ <function>clock_timestamp()</>, it returns the actual current time,
6245
+ but as a formatted <type>text</> string rather than a <type>timestamp
6246
+ with time zone</> value.
6220
6247
</para>
6221
6248
6222
6249
<para>
6223
6250
All the date/time data types also accept the special literal value
6224
- <literal>now</literal> to specify the current date and time. Thus,
6251
+ <literal>now</literal> to specify the current date and time (again,
6252
+ interpreted as the transaction start time). Thus,
6225
6253
the following three all return the same result:
6226
6254
<programlisting>
6227
6255
SELECT CURRENT_TIMESTAMP;
0 commit comments