pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
gettime() - a timeofday() alternative
12+ messages / 6 participants
[nested] [flat]

* gettime() - a timeofday() alternative
@ 2005-08-07 06:10  Brendan Jurd <direvus@gmail.com>
  0 siblings, 2 replies; 12+ messages in thread

From: Brendan Jurd @ 2005-08-07 06:10 UTC (permalink / raw)
  To: pgsql-hackers

Hi all,

I propose to add an internal function gettime() that transparently
returns the current system time, as a timestamptz with maximum
precision.

Calling gettime() would be a more elegant approach than calling
timeofday() and converting it to a timestamp, and avoids some of the
potential problems in that conversion (such as "Sat" being
misinterpreted as an Australian timezone).

I'm open to alternate suggestions for the name of the function.

If there are no objections, I'll start cooking up a patch right away.

-- 
BJ



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: gettime() - a timeofday() alternative
@ 2005-08-08 08:16  Brendan Jurd <direvus@gmail.com>
  parent: Brendan Jurd <direvus@gmail.com>
  1 sibling, 1 reply; 12+ messages in thread

From: Brendan Jurd @ 2005-08-08 08:16 UTC (permalink / raw)
  To: pgsql-patches@postgresql.org

On 8/7/05, Brendan Jurd <direvus@gmail.com> wrote:
> Hi all,
> 
> I propose to add an internal function gettime() that transparently
> returns the current system time, as a timestamptz with maximum
> precision.
> 

Here's the patch.

The changes to pg_proc.h, timestamp.h and timestamp.c are trivial. 
The changes to func.sgml are more comprehensive; I've split the
section on Current Date/Time into two subsections, one that explains
the transaction time functions and one for the system time functions.

-- 
BJ

Attachments: download all (4 files, .tar.gz)

timestamp.h.diff (application/octet-stream, 602B) download Index: src/include/utils/timestamp.h =================================================================== RCS file: /projects/cvsroot/pgsql/src/include/utils/timestamp.h,v retrieving revision 1.53 diff -C3 -r1.53 timestamp.h *** src/include/utils/timestamp.h 22 Jul 2005 05:08:26 -0000 1.53 --- src/include/utils/timestamp.h 7 Aug 2005 13:43:24 -0000 *************** *** 285,290 **** --- 285,291 ---- extern Datum timestamptz_part(PG_FUNCTION_ARGS); extern Datum now(PG_FUNCTION_ARGS); + extern Datum gettime(PG_FUNCTION_ARGS); extern Datum pgsql_postmaster_start_time(PG_FUNCTION_ARGS);
pg_proc.h.diff (application/octet-stream, 1.0K) download Index: src/include/catalog/pg_proc.h =================================================================== RCS file: /projects/cvsroot/pgsql/src/include/catalog/pg_proc.h,v retrieving revision 1.380 diff -C3 -r1.380 pg_proc.h *** src/include/catalog/pg_proc.h 2 Aug 2005 16:11:57 -0000 1.380 --- src/include/catalog/pg_proc.h 7 Aug 2005 13:43:36 -0000 *************** *** 1420,1425 **** --- 1420,1427 ---- DESCR("not equal"); DATA(insert OID = 1107 ( time_cmp PGNSP PGUID 12 f f t f i 2 23 "1083 1083" _null_ _null_ _null_ time_cmp - _null_ )); DESCR("less-equal-greater"); + DATA(insert OID = 1136 ( gettime PGNSP PGUID 12 f f t f v 0 1184 "" _null_ _null_ _null_ gettime - _null_ )); + DESCR("current transaction time"); DATA(insert OID = 1138 ( date_larger PGNSP PGUID 12 f f t f i 2 1082 "1082 1082" _null_ _null_ _null_ date_larger - _null_ )); DESCR("larger of two"); DATA(insert OID = 1139 ( date_smaller PGNSP PGUID 12 f f t f i 2 1082 "1082 1082" _null_ _null_ _null_ date_smaller - _null_ ));
timestamp.c.diff (application/octet-stream, 621B) download Index: src/backend/utils/adt/timestamp.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v retrieving revision 1.147 diff -C3 -r1.147 timestamp.c *** src/backend/utils/adt/timestamp.c 30 Jul 2005 18:20:44 -0000 1.147 --- src/backend/utils/adt/timestamp.c 7 Aug 2005 13:44:58 -0000 *************** *** 920,925 **** --- 920,931 ---- } Datum + gettime(PG_FUNCTION_ARGS) + { + PG_RETURN_TIMESTAMPTZ(GetCurrentTimestamp()); + } + + Datum pgsql_postmaster_start_time(PG_FUNCTION_ARGS) { PG_RETURN_TIMESTAMPTZ(PgStartTime);
func.sgml.diff (application/octet-stream, 11.1K) download Index: doc/src/sgml/func.sgml =================================================================== RCS file: /projects/cvsroot/pgsql/doc/src/sgml/func.sgml,v retrieving revision 1.276 diff -C3 -r1.276 func.sgml *** doc/src/sgml/func.sgml 2 Aug 2005 16:11:56 -0000 1.276 --- doc/src/sgml/func.sgml 7 Aug 2005 13:45:47 -0000 *************** *** 5047,5053 **** <row> <entry><literal><function>current_date</function></literal></entry> <entry><type>date</type></entry> ! <entry>Today's date; see <xref linkend="functions-datetime-current"> </entry> <entry></entry> <entry></entry> --- 5047,5053 ---- <row> <entry><literal><function>current_date</function></literal></entry> <entry><type>date</type></entry> ! <entry>Today's date; see <xref linkend="functions-datetime-current-xact"> </entry> <entry></entry> <entry></entry> *************** *** 5056,5062 **** <row> <entry><literal><function>current_time</function></literal></entry> <entry><type>time with time zone</type></entry> ! <entry>Time of day; see <xref linkend="functions-datetime-current"> </entry> <entry></entry> <entry></entry> --- 5056,5062 ---- <row> <entry><literal><function>current_time</function></literal></entry> <entry><type>time with time zone</type></entry> ! <entry>Time of day; see <xref linkend="functions-datetime-current-xact"> </entry> <entry></entry> <entry></entry> *************** *** 5065,5071 **** <row> <entry><literal><function>current_timestamp</function></literal></entry> <entry><type>timestamp with time zone</type></entry> ! <entry>Date and time; see <xref linkend="functions-datetime-current"> </entry> <entry></entry> <entry></entry> --- 5065,5071 ---- <row> <entry><literal><function>current_timestamp</function></literal></entry> <entry><type>timestamp with time zone</type></entry> ! <entry>Date and time; see <xref linkend="functions-datetime-current-xact"> </entry> <entry></entry> <entry></entry> *************** *** 5121,5126 **** --- 5121,5134 ---- </row> <row> + <entry><literal><function>gettime</function>()</literal></entry> + <entry><type>timestamp with time zone</type></entry> + <entry>Current system date and time; see <xref linkend="functions-datetime-current-system"></entry> + <entry></entry> + <entry></entry> + </row> + + <row> <entry><literal><function>isfinite</function>(<type>timestamp</type>)</literal></entry> <entry><type>boolean</type></entry> <entry>Test for finite time stamp (not equal to infinity)</entry> *************** *** 5155,5161 **** <row> <entry><literal><function>localtime</function></literal></entry> <entry><type>time</type></entry> ! <entry>Time of day; see <xref linkend="functions-datetime-current"> </entry> <entry></entry> <entry></entry> --- 5163,5169 ---- <row> <entry><literal><function>localtime</function></literal></entry> <entry><type>time</type></entry> ! <entry>Time of day; see <xref linkend="functions-datetime-current-xact"> </entry> <entry></entry> <entry></entry> *************** *** 5164,5170 **** <row> <entry><literal><function>localtimestamp</function></literal></entry> <entry><type>timestamp</type></entry> ! <entry>Date and time; see <xref linkend="functions-datetime-current"> </entry> <entry></entry> <entry></entry> --- 5172,5178 ---- <row> <entry><literal><function>localtimestamp</function></literal></entry> <entry><type>timestamp</type></entry> ! <entry>Date and time; see <xref linkend="functions-datetime-current-xact"> </entry> <entry></entry> <entry></entry> *************** *** 5174,5180 **** <entry><literal><function>now</function>()</literal></entry> <entry><type>timestamp with time zone</type></entry> <entry>Current date and time (equivalent to ! <function>current_timestamp</function>); see <xref linkend="functions-datetime-current"> </entry> <entry></entry> <entry></entry> --- 5182,5188 ---- <entry><literal><function>now</function>()</literal></entry> <entry><type>timestamp with time zone</type></entry> <entry>Current date and time (equivalent to ! <function>current_timestamp</function>); see <xref linkend="functions-datetime-current-xact"> </entry> <entry></entry> <entry></entry> *************** *** 5183,5189 **** <row> <entry><literal><function>timeofday</function>()</literal></entry> <entry><type>text</type></entry> ! <entry>Current date and time; see <xref linkend="functions-datetime-current"> </entry> <entry></entry> <entry></entry> --- 5191,5197 ---- <row> <entry><literal><function>timeofday</function>()</literal></entry> <entry><type>text</type></entry> ! <entry>Current system date and time (textual representation); see <xref linkend="functions-datetime-current-system"> </entry> <entry></entry> <entry></entry> *************** *** 5769,5777 **** <secondary>current</secondary> </indexterm> ! <para> ! The following functions are available to obtain the current date and/or ! time: <synopsis> CURRENT_DATE CURRENT_TIME --- 5777,5788 ---- <secondary>current</secondary> </indexterm> ! <sect3 id="functions-datetime-current-xact"> ! <title>Transaction Time</title> ! ! <para> ! The following functions are available to determine the date/time as at the start of the current transaction: ! <synopsis> CURRENT_DATE CURRENT_TIME *************** *** 5811,5818 **** </para> </note> ! <para> ! Some examples: <screen> SELECT CURRENT_TIME; <lineannotation>Result: </lineannotation><computeroutput>14:39:53.662522-05</computeroutput> --- 5822,5829 ---- </para> </note> ! <para> ! Some examples: <screen> SELECT CURRENT_TIME; <lineannotation>Result: </lineannotation><computeroutput>14:39:53.662522-05</computeroutput> *************** *** 5829,5882 **** SELECT LOCALTIMESTAMP; <lineannotation>Result: </lineannotation><computeroutput>2001-12-23 14:39:53.662522</computeroutput> </screen> ! </para> ! ! <para> ! The function <function>now()</function> is the traditional ! <productname>PostgreSQL</productname> equivalent to ! <function>CURRENT_TIMESTAMP</function>. ! </para> ! <para> ! It is important to know that ! <function>CURRENT_TIMESTAMP</function> and related functions return ! the start time of the current transaction; their values do not ! change during the transaction. This is considered a feature: ! the intent is to allow a single transaction to have a consistent ! notion of the <quote>current</quote> time, so that multiple ! modifications within the same transaction bear the same ! time stamp. ! </para> - <note> <para> ! Other database systems may advance these values more ! frequently. </para> - </note> ! <para> ! There is also the function <function>timeofday()</function> which ! returns the wall-clock time and advances during transactions. For ! historical reasons <function>timeofday()</function> returns a ! <type>text</type> string rather than a <type>timestamp</type> ! value: ! <screen> ! SELECT timeofday(); ! <lineannotation>Result: </lineannotation><computeroutput>Sat Feb 17 19:07:32.000126 2001 EST</computeroutput> ! </screen> ! </para> ! <para> ! All the date/time data types also accept the special literal value ! <literal>now</literal> to specify the current date and time. Thus, ! the following three all return the same result: ! <programlisting> ! SELECT CURRENT_TIMESTAMP; ! SELECT now(); ! SELECT TIMESTAMP 'now'; -- incorrect for use with DEFAULT ! </programlisting> ! </para> <tip> <para> --- 5840,5886 ---- SELECT LOCALTIMESTAMP; <lineannotation>Result: </lineannotation><computeroutput>2001-12-23 14:39:53.662522</computeroutput> </screen> ! </para> ! <para> ! The function <function>now()</function> is the traditional ! <productname>PostgreSQL</productname> equivalent to ! <function>CURRENT_TIMESTAMP</function>. ! </para> <para> ! It is important to know that ! <function>CURRENT_TIMESTAMP</function> and related functions return ! the start time of the current transaction; their values do not ! change during the transaction. This is considered a feature: ! the intent is to allow a single transaction to have a consistent ! notion of the <quote>current</quote> time, so that multiple ! modifications within the same transaction bear the same ! time stamp. </para> ! <note> ! <para> ! Other database systems may advance these values more ! frequently. ! </para> ! </note> ! <para> ! If you want to access the current time without regard to the current ! transaction, refer to the functions in <xref linkend="functions-datetime-current-system">. ! </para> ! ! <para> ! All the date/time data types also accept the special literal value ! <literal>now</literal> to specify the current date and time. Thus, ! the following three all return the same result: ! <programlisting> ! SELECT CURRENT_TIMESTAMP; ! SELECT now(); ! SELECT TIMESTAMP 'now'; -- incorrect for use with DEFAULT ! </programlisting> ! </para> <tip> <para> *************** *** 5890,5895 **** --- 5894,5934 ---- behavior of defaulting to the time of row insertion. </para> </tip> + </sect3> + + <sect3 id="functions-datetime-current-system"> + <title>System Time</title> + + <para> + The following functions are available to determine the current system time directly: + + <synopsis> + gettime() + timeofday() + </synopsis> + </para> + + <para> + <function>gettime()</function> returns type <type>timestamp with time zone</type> at the maximum available precision. + </para> + + <para> + <function>timeofday()</function> returns a long textual representation of the current time type <type>text</type>. + </para> + + <para> + Usage examples: + <screen> + SELECT gettime(); + <lineannotation>Result: </lineannotation><computeroutput>2005-08-07 21:22:43.495743+10</computeroutput> + + SELECT timeofday(); + <lineannotation>Result: </lineannotation><computeroutput>Sat Feb 17 19:07:32.000126 2001 EST</computeroutput> + </screen> + </para> + + </sect3> + </sect2> </sect1>
^ permalink raw reply [nested|flat] 12+ messages in thread

* Re: gettime() - a timeofday() alternative
@ 2005-08-13 02:34  Bruce Momjian <pgman@candle.pha.pa.us>
  parent: Brendan Jurd <direvus@gmail.com>
  1 sibling, 1 reply; 12+ messages in thread

From: Bruce Momjian @ 2005-08-13 02:34 UTC (permalink / raw)
  To: Brendan Jurd <direvus@gmail.com>; +Cc: pgsql-hackers

Brendan Jurd wrote:
> Hi all,
> 
> I propose to add an internal function gettime() that transparently
> returns the current system time, as a timestamptz with maximum
> precision.
> 
> Calling gettime() would be a more elegant approach than calling
> timeofday() and converting it to a timestamp, and avoids some of the
> potential problems in that conversion (such as "Sat" being
> misinterpreted as an Australian timezone).
> 
> I'm open to alternate suggestions for the name of the function.
> 
> If there are no objections, I'll start cooking up a patch right away.

We already have a TODO for this:
	
	* Add transaction_timestamp(), statement_timestamp(), clock_timestamp()
	  functionality
	
	  Current CURRENT_TIMESTAMP returns the start time of the current
	  transaction, and gettimeofday() returns the wallclock time. This will
	  make time reporting more consistent and will allow reporting of
	  the statement start time.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: gettime() - a timeofday() alternative
@ 2005-08-13 02:36  Bruce Momjian <pgman@candle.pha.pa.us>
  parent: Brendan Jurd <direvus@gmail.com>
  0 siblings, 0 replies; 12+ messages in thread

From: Bruce Momjian @ 2005-08-13 02:36 UTC (permalink / raw)
  To: Brendan Jurd <direvus@gmail.com>; +Cc: pgsql-patches@postgresql.org


This has been saved for the 8.2 release:

	http://momjian.postgresql.org/cgi-bin/pgpatches_hold

---------------------------------------------------------------------------

Brendan Jurd wrote:
> On 8/7/05, Brendan Jurd <direvus@gmail.com> wrote:
> > Hi all,
> > 
> > I propose to add an internal function gettime() that transparently
> > returns the current system time, as a timestamptz with maximum
> > precision.
> > 
> 
> Here's the patch.
> 
> The changes to pg_proc.h, timestamp.h and timestamp.c are trivial. 
> The changes to func.sgml are more comprehensive; I've split the
> section on Current Date/Time into two subsections, one that explains
> the transaction time functions and one for the system time functions.
> 
> -- 
> BJ

[ Attachment, skipping... ]

[ Attachment, skipping... ]

[ Attachment, skipping... ]

[ Attachment, skipping... ]

> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
>        subscribe-nomail command to majordomo@postgresql.org so that your
>        message can get through to the mailing list cleanly

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: gettime() - a timeofday() alternative
@ 2005-08-13 06:30  Brendan Jurd <direvus@gmail.com>
  parent: Bruce Momjian <pgman@candle.pha.pa.us>
  0 siblings, 1 reply; 12+ messages in thread

From: Brendan Jurd @ 2005-08-13 06:30 UTC (permalink / raw)
  To: Bruce Momjian <pgman@candle.pha.pa.us>; +Cc: pgsql-hackers

> We already have a TODO for this:
> 
>         * Add transaction_timestamp(), statement_timestamp(), clock_timestamp()
>           functionality

I like the idea of having a function for statement start time.  I
think I'll incorporate it into my patch.

The suggested naming convention in the TODO is good as well.  I'd be
inclined to make those  *_timestamp() functions the core functions,
and then make things like now() and gettime() shorthand equivalents.



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: gettime() - a timeofday() alternative
@ 2005-08-13 19:51  Brendan Jurd <direvus@gmail.com>
  parent: Brendan Jurd <direvus@gmail.com>
  0 siblings, 2 replies; 12+ messages in thread

From: Brendan Jurd @ 2005-08-13 19:51 UTC (permalink / raw)
  To: Bruce Momjian <pgman@candle.pha.pa.us>; pgsql-hackers

On 8/14/05, Bruce Momjian <pgman@candle.pha.pa.us> wrote:
> Brendan Jurd wrote:
> > > We already have a TODO for this:
> > >
> > >         * Add transaction_timestamp(), statement_timestamp(), clock_timestamp()
> > >           functionality
> >
> > I like the idea of having a function for statement start time.  I
> > think I'll incorporate it into my patch.
> >

Regarding the statement_timestamp() ... if the entire query path is
parser -> rewriter -> planner/optimiser -> executor, what point in
that path would be considered the true start of the "statement"?  I
would assume that it's right at the beginning, when it is first handed
to the parser, but that's a very naive assumption.



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: gettime() - a timeofday() alternative
@ 2005-08-13 21:35  mark@mark.mielke.cc
  parent: Brendan Jurd <direvus@gmail.com>
  1 sibling, 0 replies; 12+ messages in thread

From: mark@mark.mielke.cc @ 2005-08-13 21:35 UTC (permalink / raw)
  To: Brendan Jurd <direvus@gmail.com>; +Cc: Bruce Momjian <pgman@candle.pha.pa.us>; pgsql-hackers

On Sun, Aug 14, 2005 at 05:51:16AM +1000, Brendan Jurd wrote:
> Regarding the statement_timestamp() ... if the entire query path is
> parser -> rewriter -> planner/optimiser -> executor, what point in
> that path would be considered the true start of the "statement"?  I
> would assume that it's right at the beginning, when it is first handed
> to the parser, but that's a very naive assumption.

The latest time before any index or table has been accessed to derive
results?

For prepared statements, for example, the time the statement was prepared
doesn't seem useful to me.

Cheers,
mark

-- 
mark@mielke.cc / markm@ncf.ca / markm@nortel.com     __________________________
.  .  _  ._  . .   .__    .  . ._. .__ .   . . .__  | Neighbourhood Coder
|\/| |_| |_| |/    |_     |\/|  |  |_  |   |/  |_   | 
|  | | | | \ | \   |__ .  |  | .|. |__ |__ | \ |__  | Ottawa, Ontario, Canada

  One ring to rule them all, one ring to find them, one ring to bring them all
                       and in the darkness bind them...

                           http://mark.mielke.cc/




^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: gettime() - a timeofday() alternative
@ 2005-08-13 22:24  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Brendan Jurd <direvus@gmail.com>
  1 sibling, 1 reply; 12+ messages in thread

From: Tom Lane @ 2005-08-13 22:24 UTC (permalink / raw)
  To: Brendan Jurd <direvus@gmail.com>; +Cc: Bruce Momjian <pgman@candle.pha.pa.us>; pgsql-hackers

Brendan Jurd <direvus@gmail.com> writes:
> Regarding the statement_timestamp() ... if the entire query path is
> parser -> rewriter -> planner/optimiser -> executor, what point in
> that path would be considered the true start of the "statement"?

IIRC, what we actually intended that to mean is the time of receipt of
the current interactive command --- that is, it gets set in the
postgres.c outer loop, not anywhere in the parser/etc path.  Otherwise
there's not a unique answer (consider statements issued inside SQL
functions for instance).

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: gettime() - a timeofday() alternative
@ 2005-08-17 22:07  Jim C. Nasby <jnasby@pervasive.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 12+ messages in thread

From: Jim C. Nasby @ 2005-08-17 22:07 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Brendan Jurd <direvus@gmail.com>; Bruce Momjian <pgman@candle.pha.pa.us>; pgsql-hackers

On Sat, Aug 13, 2005 at 06:24:01PM -0400, Tom Lane wrote:
> Brendan Jurd <direvus@gmail.com> writes:
> > Regarding the statement_timestamp() ... if the entire query path is
> > parser -> rewriter -> planner/optimiser -> executor, what point in
> > that path would be considered the true start of the "statement"?
> 
> IIRC, what we actually intended that to mean is the time of receipt of
> the current interactive command --- that is, it gets set in the
> postgres.c outer loop, not anywhere in the parser/etc path.  Otherwise
> there's not a unique answer (consider statements issued inside SQL
> functions for instance).

ISTM that it would be useful to be able to use timestamp_statement
within a function though... although I guess timestamp_clock might
suffice in most cases. Another consideration is that this is a potential
source of confusion; people could easily think that timestamp_statement
would operate the same inside a function as it would outside.

Would it be reasonable to add one more timestamp that works the same
inside and outside a function? In either case, can anyone think of a
less-ambiguous name for timestamp_statement?
-- 
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software        http://pervasive.com        512-569-9461



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: gettime() - a timeofday() alternative
@ 2005-08-17 22:08  Bruce Momjian <pgman@candle.pha.pa.us>
  parent: Jim C. Nasby <jnasby@pervasive.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Bruce Momjian @ 2005-08-17 22:08 UTC (permalink / raw)
  To: Jim C. Nasby <jnasby@pervasive.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Brendan Jurd <direvus@gmail.com>; pgsql-hackers

Jim C. Nasby wrote:
> On Sat, Aug 13, 2005 at 06:24:01PM -0400, Tom Lane wrote:
> > Brendan Jurd <direvus@gmail.com> writes:
> > > Regarding the statement_timestamp() ... if the entire query path is
> > > parser -> rewriter -> planner/optimiser -> executor, what point in
> > > that path would be considered the true start of the "statement"?
> > 
> > IIRC, what we actually intended that to mean is the time of receipt of
> > the current interactive command --- that is, it gets set in the
> > postgres.c outer loop, not anywhere in the parser/etc path.  Otherwise
> > there's not a unique answer (consider statements issued inside SQL
> > functions for instance).
> 
> ISTM that it would be useful to be able to use timestamp_statement
> within a function though... although I guess timestamp_clock might
> suffice in most cases. Another consideration is that this is a potential
> source of confusion; people could easily think that timestamp_statement
> would operate the same inside a function as it would outside.
> 
> Would it be reasonable to add one more timestamp that works the same
> inside and outside a function? In either case, can anyone think of a
> less-ambiguous name for timestamp_statement?

timestamp_client_statement?  That highlights it is when the client sends
the statement.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: gettime() - a timeofday() alternative
@ 2005-08-17 22:17  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Bruce Momjian <pgman@candle.pha.pa.us>
  0 siblings, 0 replies; 12+ messages in thread

From: Tom Lane @ 2005-08-17 22:17 UTC (permalink / raw)
  To: Bruce Momjian <pgman@candle.pha.pa.us>; +Cc: Jim C. Nasby <jnasby@pervasive.com>; Brendan Jurd <direvus@gmail.com>; pgsql-hackers

Bruce Momjian <pgman@candle.pha.pa.us> writes:
> Jim C. Nasby wrote:
>> On Sat, Aug 13, 2005 at 06:24:01PM -0400, Tom Lane wrote:
>>> IIRC, what we actually intended that to mean is the time of receipt of
>>> the current interactive command --- that is, it gets set in the
>>> postgres.c outer loop, not anywhere in the parser/etc path.  Otherwise
>>> there's not a unique answer (consider statements issued inside SQL
>>> functions for instance).

>> Would it be reasonable to add one more timestamp that works the same
>> inside and outside a function? In either case, can anyone think of a
>> less-ambiguous name for timestamp_statement?

> timestamp_client_statement?  That highlights it is when the client sends
> the statement.

timestamp_command, maybe, would convey the right image.

(I don't think we need yet a fourth flavor of this, nor do I see anything
about it that "works differently inside and outside a function".)

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: gettime() - a timeofday() alternative
@ 2005-08-17 22:27  Jim Nasby <jnasby@pervasive.com>
  0 siblings, 0 replies; 12+ messages in thread

From: Jim Nasby @ 2005-08-17 22:27 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; Bruce Momjian <pgman@candle.pha.pa.us>; +Cc: Brendan Jurd <direvus@gmail.com>; pgsql-hackers

> From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > Jim C. Nasby wrote:
> >> On Sat, Aug 13, 2005 at 06:24:01PM -0400, Tom Lane wrote:
> >>> IIRC, what we actually intended that to mean is the time 
> of receipt of
> >>> the current interactive command --- that is, it gets set in the
> >>> postgres.c outer loop, not anywhere in the parser/etc 
> path.  Otherwise
> >>> there's not a unique answer (consider statements issued inside SQL
> >>> functions for instance).
> 
> >> Would it be reasonable to add one more timestamp that 
> works the same
> >> inside and outside a function? In either case, can anyone 
> think of a
> >> less-ambiguous name for timestamp_statement?
> 
> > timestamp_client_statement?  That highlights it is when the 
> client sends
> > the statement.
> 
> timestamp_command, maybe, would convey the right image.
> 
> (I don't think we need yet a fourth flavor of this, nor do I 
> see anything
> about it that "works differently inside and outside a function".)

Here's what I thought was going to happen:

psql> BEGIN; -- sets timestamp_transaction();
psql> SELECT func1(); -- sets timestamp_statement()
func1:
SELECT something; -- doesn't set timestamp_statement(), because it's in a function
call func2();
return;
psql> SELECT something; -- sets timestamp_statement() again

Maybe I just mis-understood and each statement that's issued will update timestamp_statement(). If that's the case I think we're fine (I can't really think of a use-case for timestamp_command() myself...).

OTOH, if the intention is to do what I outlined in the above timeline, I think we should also have timestamp_command(), and change timestamp_statement() so that it always indicates the timestamp at the start of the current statement.
--
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software        http://pervasive.com        512-569-9461 



^ permalink  raw  reply  [nested|flat] 12+ messages in thread


end of thread, other threads:[~2005-08-17 22:27 UTC | newest]

Thread overview: 12+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-08-07 06:10 gettime() - a timeofday() alternative Brendan Jurd <direvus@gmail.com>
2005-08-08 08:16 ` Brendan Jurd <direvus@gmail.com>
2005-08-13 02:36   ` Bruce Momjian <pgman@candle.pha.pa.us>
2005-08-13 02:34 ` Bruce Momjian <pgman@candle.pha.pa.us>
2005-08-13 06:30   ` Brendan Jurd <direvus@gmail.com>
2005-08-13 19:51     ` Brendan Jurd <direvus@gmail.com>
2005-08-13 21:35       ` mark@mark.mielke.cc
2005-08-13 22:24       ` Tom Lane <tgl@sss.pgh.pa.us>
2005-08-17 22:07         ` Jim C. Nasby <jnasby@pervasive.com>
2005-08-17 22:08           ` Bruce Momjian <pgman@candle.pha.pa.us>
2005-08-17 22:17             ` Tom Lane <tgl@sss.pgh.pa.us>
2005-08-17 22:27 Re: gettime() - a timeofday() alternative Jim Nasby <jnasby@pervasive.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox