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 $ -->
22
33 <chapter id="functions">
44 <title>Functions and Operators</title>
@@ -5357,7 +5357,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
53575357 <row>
53585358 <entry><literal><function>current_date</function></literal></entry>
53595359 <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">
53615362 </entry>
53625363 <entry></entry>
53635364 <entry></entry>
@@ -5366,7 +5367,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
53665367 <row>
53675368 <entry><literal><function>current_time</function></literal></entry>
53685369 <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">
53705372 </entry>
53715373 <entry></entry>
53725374 <entry></entry>
@@ -5375,7 +5377,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
53755377 <row>
53765378 <entry><literal><function>current_timestamp</function></literal></entry>
53775379 <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">
53795382 </entry>
53805383 <entry></entry>
53815384 <entry></entry>
@@ -5384,8 +5387,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
53845387 <row>
53855388 <entry><literal><function>date_part</function>(<type>text</type>, <type>timestamp</type>)</literal></entry>
53865389 <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">
53895392 </entry>
53905393 <entry><literal>date_part('hour', timestamp '2001-02-16 20:38:40')</literal></entry>
53915394 <entry><literal>20</literal></entry>
@@ -5473,7 +5476,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
54735476 <row>
54745477 <entry><literal><function>localtime</function></literal></entry>
54755478 <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">
54775481 </entry>
54785482 <entry></entry>
54795483 <entry></entry>
@@ -5482,7 +5486,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
54825486 <row>
54835487 <entry><literal><function>localtimestamp</function></literal></entry>
54845488 <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">
54865491 </entry>
54875492 <entry></entry>
54885493 <entry></entry>
@@ -5491,8 +5496,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
54915496 <row>
54925497 <entry><literal><function>now</function>()</literal></entry>
54935498 <entry><type>timestamp with time zone</type></entry>
5494- <entry>Date and timeof 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">
54965501 </entry>
54975502 <entry></entry>
54985503 <entry></entry>
@@ -5501,8 +5506,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
55015506 <row>
55025507 <entry><literal><function>transaction_timestamp</function>()</literal></entry>
55035508 <entry><type>timestamp with time zone</type></entry>
5504- <entry>Date and timeof 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">
55065511 </entry>
55075512 <entry></entry>
55085513 <entry></entry>
@@ -5511,7 +5516,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
55115516 <row>
55125517 <entry><literal><function>statement_timestamp</function>()</literal></entry>
55135518 <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">
55155521 </entry>
55165522 <entry></entry>
55175523 <entry></entry>
@@ -5520,7 +5526,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
55205526 <row>
55215527 <entry><literal><function>clock_timestamp</function>()</literal></entry>
55225528 <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">
55245531 </entry>
55255532 <entry></entry>
55265533 <entry></entry>
@@ -5529,8 +5536,9 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
55295536 <row>
55305537 <entry><literal><function>timeofday</function>()</literal></entry>
55315538 <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">
55345542 </entry>
55355543 <entry></entry>
55365544 <entry></entry>
@@ -6118,7 +6126,7 @@ SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'MST';
61186126 </sect2>
61196127
61206128 <sect2 id="functions-datetime-current">
6121- <title>Date/Time of Transaction Start </title>
6129+ <title>Current Date/Time</title>
61226130
61236131 <indexterm>
61246132 <primary>date</primary>
@@ -6131,8 +6139,10 @@ SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'MST';
61316139 </indexterm>
61326140
61336141 <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:
61366146<synopsis>
61376147CURRENT_DATE
61386148CURRENT_TIME
@@ -6185,43 +6195,61 @@ SELECT LOCALTIMESTAMP;
61856195 </para>
61866196
61876197 <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
61916200 change during the transaction. This is considered a feature:
61926201 the intent is to allow a single transaction to have a consistent
61936202 notion of the <quote>current</quote> time, so that multiple
61946203 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.
61986205 </para>
61996206
6207+ <note>
6208+ <para>
6209+ Other database systems may advance these values more
6210+ frequently.
6211+ </para>
6212+ </note>
6213+
62006214 <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>
62086226 </para>
62096227
62106228 <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.
62206247 </para>
62216248
62226249 <para>
62236250 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,
62256253 the following three all return the same result:
62266254<programlisting>
62276255SELECT CURRENT_TIMESTAMP;