Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
eaf8f312
Commit
eaf8f312
authored
Jun 19, 2006
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some editorial work on the documentation of the current-date/time
functions.
parent
aaf125f8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
42 deletions
+70
-42
doc/src/sgml/func.sgml
doc/src/sgml/func.sgml
+70
-42
No files found.
doc/src/sgml/func.sgml
View file @
eaf8f312
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.32
2 2006/06/18 15:38:35 petere
Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.32
3 2006/06/19 16:13:01 tgl
Exp $ -->
<chapter id="functions">
<chapter id="functions">
<title>Functions and Operators</title>
<title>Functions and Operators</title>
...
@@ -5357,7 +5357,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
...
@@ -5357,7 +5357,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
<row>
<row>
<entry><literal><function>current_date</function></literal></entry>
<entry><literal><function>current_date</function></literal></entry>
<entry><type>date</type></entry>
<entry><type>date</type></entry>
<entry>Today's date; see <xref linkend="functions-datetime-current">
<entry>Current date;
see <xref linkend="functions-datetime-current">
</entry>
</entry>
<entry></entry>
<entry></entry>
<entry></entry>
<entry></entry>
...
@@ -5366,7 +5367,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
...
@@ -5366,7 +5367,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
<row>
<row>
<entry><literal><function>current_time</function></literal></entry>
<entry><literal><function>current_time</function></literal></entry>
<entry><type>time with time zone</type></entry>
<entry><type>time with time zone</type></entry>
<entry>Time of day; see <xref linkend="functions-datetime-current">
<entry>Current time of day;
see <xref linkend="functions-datetime-current">
</entry>
</entry>
<entry></entry>
<entry></entry>
<entry></entry>
<entry></entry>
...
@@ -5375,7 +5377,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
...
@@ -5375,7 +5377,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
<row>
<row>
<entry><literal><function>current_timestamp</function></literal></entry>
<entry><literal><function>current_timestamp</function></literal></entry>
<entry><type>timestamp with time zone</type></entry>
<entry><type>timestamp with time zone</type></entry>
<entry>Date and time of start of current transaction; see <xref linkend="functions-datetime-current">
<entry>Current date and time (start of current transaction);
see <xref linkend="functions-datetime-current">
</entry>
</entry>
<entry></entry>
<entry></entry>
<entry></entry>
<entry></entry>
...
@@ -5384,8 +5387,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
...
@@ -5384,8 +5387,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
<row>
<row>
<entry><literal><function>date_part</function>(<type>text</type>, <type>timestamp</type>)</literal></entry>
<entry><literal><function>date_part</function>(<type>text</type>, <type>timestamp</type>)</literal></entry>
<entry><type>double precision</type></entry>
<entry><type>double precision</type></entry>
<entry>Get subfield (equivalent to
<entry>Get subfield (equivalent to
<function>extract</function>);
<function>extract</function>);
see <xref linkend="functions-datetime-extract">
see <xref linkend="functions-datetime-extract">
</entry>
</entry>
<entry><literal>date_part('hour', timestamp '2001-02-16 20:38:40')</literal></entry>
<entry><literal>date_part('hour', timestamp '2001-02-16 20:38:40')</literal></entry>
<entry><literal>20</literal></entry>
<entry><literal>20</literal></entry>
...
@@ -5473,7 +5476,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
...
@@ -5473,7 +5476,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
<row>
<row>
<entry><literal><function>localtime</function></literal></entry>
<entry><literal><function>localtime</function></literal></entry>
<entry><type>time</type></entry>
<entry><type>time</type></entry>
<entry>Time of day; see <xref linkend="functions-datetime-current">
<entry>Current time of day;
see <xref linkend="functions-datetime-current">
</entry>
</entry>
<entry></entry>
<entry></entry>
<entry></entry>
<entry></entry>
...
@@ -5482,7 +5486,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
...
@@ -5482,7 +5486,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
<row>
<row>
<entry><literal><function>localtimestamp</function></literal></entry>
<entry><literal><function>localtimestamp</function></literal></entry>
<entry><type>timestamp</type></entry>
<entry><type>timestamp</type></entry>
<entry>Date and time; see <xref linkend="functions-datetime-current">
<entry>Current date and time (start of current transaction);
see <xref linkend="functions-datetime-current">
</entry>
</entry>
<entry></entry>
<entry></entry>
<entry></entry>
<entry></entry>
...
@@ -5491,8 +5496,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
...
@@ -5491,8 +5496,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
<row>
<row>
<entry><literal><function>now</function>()</literal></entry>
<entry><literal><function>now</function>()</literal></entry>
<entry><type>timestamp with time zone</type></entry>
<entry><type>timestamp with time zone</type></entry>
<entry>
Date and time of start of current transaction (equivalent to
<entry>
Current date and time (start of current transaction);
<function>CURRENT_TIMESTAMP</function>);
see <xref linkend="functions-datetime-current">
see <xref linkend="functions-datetime-current">
</entry>
</entry>
<entry></entry>
<entry></entry>
<entry></entry>
<entry></entry>
...
@@ -5501,8 +5506,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
...
@@ -5501,8 +5506,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
<row>
<row>
<entry><literal><function>transaction_timestamp</function>()</literal></entry>
<entry><literal><function>transaction_timestamp</function>()</literal></entry>
<entry><type>timestamp with time zone</type></entry>
<entry><type>timestamp with time zone</type></entry>
<entry>
Date and time of start of current transaction (equivalent to
<entry>
Current date and time (start of current transaction);
<function>CURRENT_TIMESTAMP</function>);
see <xref linkend="functions-datetime-current">
see <xref linkend="functions-datetime-current">
</entry>
</entry>
<entry></entry>
<entry></entry>
<entry></entry>
<entry></entry>
...
@@ -5511,7 +5516,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
...
@@ -5511,7 +5516,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
<row>
<row>
<entry><literal><function>statement_timestamp</function>()</literal></entry>
<entry><literal><function>statement_timestamp</function>()</literal></entry>
<entry><type>timestamp with time zone</type></entry>
<entry><type>timestamp with time zone</type></entry>
<entry>Date and time of start of current statement; see <xref linkend="functions-datetime-current">
<entry>Current date and time (start of current statement);
see <xref linkend="functions-datetime-current">
</entry>
</entry>
<entry></entry>
<entry></entry>
<entry></entry>
<entry></entry>
...
@@ -5520,7 +5526,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
...
@@ -5520,7 +5526,8 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
<row>
<row>
<entry><literal><function>clock_timestamp</function>()</literal></entry>
<entry><literal><function>clock_timestamp</function>()</literal></entry>
<entry><type>timestamp with time zone</type></entry>
<entry><type>timestamp with time zone</type></entry>
<entry>Current date and time (changes during statement execution); see <xref linkend="functions-datetime-current">
<entry>Current date and time (changes during statement execution);
see <xref linkend="functions-datetime-current">
</entry>
</entry>
<entry></entry>
<entry></entry>
<entry></entry>
<entry></entry>
...
@@ -5529,8 +5536,9 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
...
@@ -5529,8 +5536,9 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
<row>
<row>
<entry><literal><function>timeofday</function>()</literal></entry>
<entry><literal><function>timeofday</function>()</literal></entry>
<entry><type>text</type></entry>
<entry><type>text</type></entry>
<entry>Current date and time (like <function>clock_timestamp</>), but as a Unix-style <type>text</> value;
<entry>Current date and time
see <xref linkend="functions-datetime-current">
(like <function>clock_timestamp</>, but as a <type>text</> string);
see <xref linkend="functions-datetime-current">
</entry>
</entry>
<entry></entry>
<entry></entry>
<entry></entry>
<entry></entry>
...
@@ -6118,7 +6126,7 @@ SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'MST';
...
@@ -6118,7 +6126,7 @@ SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'MST';
</sect2>
</sect2>
<sect2 id="functions-datetime-current">
<sect2 id="functions-datetime-current">
<title>
Date/Time of Transaction Start
</title>
<title>
Current Date/Time
</title>
<indexterm>
<indexterm>
<primary>date</primary>
<primary>date</primary>
...
@@ -6131,8 +6139,10 @@ SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'MST';
...
@@ -6131,8 +6139,10 @@ SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'MST';
</indexterm>
</indexterm>
<para>
<para>
The following functions are available to obtain the date and/or
<productname>PostgreSQL</productname> provides a number of functions
time of the start of the current transaction:
that return values related to the current date and time. These
SQL-standard functions all return values based on the start time of
the current transaction:
<synopsis>
<synopsis>
CURRENT_DATE
CURRENT_DATE
CURRENT_TIME
CURRENT_TIME
...
@@ -6185,43 +6195,61 @@ SELECT LOCALTIMESTAMP;
...
@@ -6185,43 +6195,61 @@ SELECT LOCALTIMESTAMP;
</para>
</para>
<para>
<para>
It is important to know that
Since these functions return
<function>CURRENT_TIMESTAMP</function> and related functions return
the start time of the current transaction, their values do not
the start time of the current transaction; their values do not
change during the transaction. This is considered a feature:
change during the transaction. This is considered a feature:
the intent is to allow a single transaction to have a consistent
the intent is to allow a single transaction to have a consistent
notion of the <quote>current</quote> time, so that multiple
notion of the <quote>current</quote> time, so that multiple
modifications within the same transaction bear the same
modifications within the same transaction bear the same
time stamp. Consider using <function>statement_timestamp</> or
time stamp.
<function>clock_timestamp</> if you need something that changes
more frequently.
</para>
</para>
<note>
<para>
Other database systems may advance these values more
frequently.
</para>
</note>
<para>
<para>
<function>CURRENT_TIMESTAMP</> might not be the
<productname>PostgreSQL</productname> also provides functions that
transaction start time on other database systems.
return the start time of the current statement, as well as the actual
For this reason, and for completeness,
current time at the instant the function is called. The complete list
<function>transaction_timestamp</> is provided.
of non-SQL-standard time functions is:
The function <function>now()</function> is the traditional
<synopsis>
<productname>PostgreSQL</productname> equivalent to
now()
the SQL-standard <function>CURRENT_TIMESTAMP</function>.
transaction_timestamp()
statement_timestamp()
clock_timestamp()
timeofday()
</synopsis>
</para>
</para>
<para>
<para>
<function>STATEMENT_TIMESTAMP</> is the time the statement
<function>now()</> is a traditional <productname>PostgreSQL</productname>
arrived at the server from the client. It is not the time
equivalent to <function>CURRENT_TIMESTAMP</function>.
the command started execution. If multiple commands were
<function>transaction_timestamp()</> is likewise equivalent to
sent as a single query string to the server, each command
<function>CURRENT_TIMESTAMP</function>, but is named to clearly reflect
has the same <function>STATEMENT_TIMESTAMP</> because they
what it returns.
all arrived at the same time. Also, commands executed
<function>statement_timestamp()</> returns the start time of the current
by server-side functions have a <function>STATEMENT_TIMESTAMP</>
statement (more specifically, the time of receipt of the latest command
based on the time the client sent the query that triggered
message from the client).
the function, not the time the function was executed.
<function>statement_timestamp()</> and <function>transaction_timestamp()</>
return the same value during the first command of a transaction, but may
differ during subsequent commands.
<function>clock_timestamp()</> returns the actual current time, and
therefore its value changes even within a single SQL command.
<function>timeofday()</> is a historical
<productname>PostgreSQL</productname> function. Like
<function>clock_timestamp()</>, it returns the actual current time,
but as a formatted <type>text</> string rather than a <type>timestamp
with time zone</> value.
</para>
</para>
<para>
<para>
All the date/time data types also accept the special literal value
All the date/time data types also accept the special literal value
<literal>now</literal> to specify the current date and time. Thus,
<literal>now</literal> to specify the current date and time (again,
interpreted as the transaction start time). Thus,
the following three all return the same result:
the following three all return the same result:
<programlisting>
<programlisting>
SELECT CURRENT_TIMESTAMP;
SELECT CURRENT_TIMESTAMP;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment