Re: clock_timestamp() and transaction_timestamp() function

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: clock_timestamp() and transaction_timestamp() function
Дата
Msg-id 200311301726.hAUHQlY09800@candle.pha.pa.us
обсуждение исходный текст
Ответ на clock_timestamp() and transaction_timestamp() function  ("Wang Mike" <itlist@msn.com>)
Ответы Re: clock_timestamp() and transaction_timestamp() function  (Peter Eisentraut <peter_e@gmx.net>)
Список pgsql-patches
We have started 7.5 development so we can now work with you to complete
this item.  Your question was what does statement_timestamp() show.
That has been discussed and it is a little tricky.  The idea is that is
should be start of a single statement that arrives from the user or is
requestd by a client.  However, this gets muddled because SPI can issue
queries and plpgsql functions can too.

I am now thinking of doing it in exec_simple_query().

I see your mailbox is now not availble so perhaps we will have to
continue this work ourselves.

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

Wang Mike wrote:
> add clock_timestamp() and transaction_timestamp() function
>
> see TODO list get more
>
> -----------------------------------------------------------------
>
> diff -u -r ../cvs/pgsql/src/backend/utils/adt/timestamp.c
> ../pgsql/src/backend/utils/adt/timestamp.c
> --- ../cvs/pgsql/src/backend/utils/adt/timestamp.c    2003-07-18
> 21:59:07.000000000 +0800
> +++ ../pgsql/src/backend/utils/adt/timestamp.c    2003-07-18
> 22:45:03.000000000 +0800
> @@ -28,6 +28,7 @@
>  #include "miscadmin.h"
>  #include "utils/array.h"
>  #include "utils/builtins.h"
> +#include "utils/nabstime.h"
>
>  /*
>   * gcc's -ffast-math switch breaks routines that expect exact results from
> @@ -835,6 +836,9 @@
>      return TRUE;
>  }    /* EncodeSpecialTimestamp() */
>
> +/* see pg_proc.h function now()  [line 1602]
> + * deleted by Xiongjian Wang (Mike Wang)
> + * Email: mikewang@zhengmai.com.cn
>  Datum
>  now(PG_FUNCTION_ARGS)
>  {
> @@ -848,6 +852,56 @@
>
>      PG_RETURN_TIMESTAMPTZ(result);
>  }
> +*/
> +
> +/*
> + * Function transaction_timestamp() return current transaction timestamp.
> + * Added by Xiongjian Wang (Mike Wang)
> + * Email: mikewang@zhengmai.com.cn
> +*/
> +Datum
> +transaction_timestamp(PG_FUNCTION_ARGS)
> +{
> +    TimestampTz result;
> +    AbsoluteTime sec;
> +    int            usec;
> +
> +    sec = GetCurrentTransactionStartTimeUsec(&usec);
> +
> +    result = AbsoluteTimeUsecToTimestampTz(sec, usec);
> +
> +    PG_RETURN_TIMESTAMPTZ(result);
> +}    /* transaction_timestamp() */
> +
> +/*
> + * Function clock_timestamp() return current clock timestamp.
> + * Added by Xiongjian Wang (Mike Wang)
> + * Email: mikewang@zhengmai.com.cn
> +*/
> +Datum
> +clock_timestamp(PG_FUNCTION_ARGS)
> +{
> +    TimestampTz result;
> +    AbsoluteTime sec;
> +    int            usec;
> +
> +    sec = GetCurrentAbsoluteTimeUsec(&usec);
> +
> +    result = AbsoluteTimeUsecToTimestampTz(sec, usec);
> +
> +    PG_RETURN_TIMESTAMPTZ(result);
> +}    /* clock_timestamp() */
> +
> +/* Please tell me what is statement_timestamp() ?
> + * Email: mikewang@zhengmai.com.cn
> +Datum
> +statement_timestamp(PG_FUNCTION_ARGS)
> +{
> +    TimestampTz result;
> +
> +    PG_RETURN_TIMESTAMPTZ(result);
> +}
> +*/
>
>  void
>  dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
> diff -u -r ../cvs/pgsql/src/include/catalog/pg_proc.h
> ../pgsql/src/include/catalog/pg_proc.h
> --- ../cvs/pgsql/src/include/catalog/pg_proc.h    2003-07-01
> 08:04:38.000000000 +0800
> +++ ../pgsql/src/include/catalog/pg_proc.h    2003-07-18 21:47:15.000000000
> +0800
> @@ -1598,7 +1598,9 @@
>  DESCR("convert date and time with time zone to timestamp with time zone");
>  DATA(insert OID = 1298 (  timetzdate_pl    PGNSP PGUID 14 f f t f i 2 1184
> "1266 1082"    "select ($2 + $1)" - _null_ ));
>  DESCR("convert time with time zone and date to timestamp with time zone");
> -DATA(insert OID = 1299 (  now               PGNSP PGUID 12 f f t f s 0 1184 ""  now
> - _null_ ));
> +
> +/* Function Now() only a alias of transaction_timestamp() */
> +DATA(insert OID = 1299 (now   PGNSP PGUID 12 f f t f s 0 1184 ""
> transaction_timestamp - _null_ ));
>  DESCR("current transaction time");
>
>  /* OIDS 1300 - 1399 */
> @@ -3406,6 +3408,12 @@
>  DESCR("I/O");
>
>
> +DATA(insert OID = 2510 (transaction_timestamp PGNSP PGUID 12 f f t f s 0
> 1184 ""  transaction_timestamp - _null_ ));
> +DESCR("current transaction time");
> +
> +DATA(insert OID = 2511 (clock_timestamp PGNSP PGUID 12 f f t f v 0 1184 ""
>  clock_timestamp - _null_ ));
> +DESCR("current clock time");
> +
>  /*
>   * Symbolic values for provolatile column: these indicate whether the
> result
>   * of a function is dependent *only* on the values of its explicit
> arguments,
> diff -u -r ../cvs/pgsql/src/include/utils/timestamp.h
> ../pgsql/src/include/utils/timestamp.h
> --- ../cvs/pgsql/src/include/utils/timestamp.h    2003-05-13
> 07:08:52.000000000 +0800
> +++ ../pgsql/src/include/utils/timestamp.h    2003-07-18 21:24:12.000000000
> +0800
> @@ -231,7 +231,9 @@
>  extern Datum timestamptz_trunc(PG_FUNCTION_ARGS);
>  extern Datum timestamptz_part(PG_FUNCTION_ARGS);
>
> -extern Datum now(PG_FUNCTION_ARGS);
> +/* extern Datum now(PG_FUNCTION_ARGS); */
> +extern Datum transaction_timestamp(PG_FUNCTION_ARGS);
> +extern Datum transaction_timestamp(PG_FUNCTION_ARGS);
>
>  /* Internal routines (not fmgr-callable) */
>
> _________________________________________________________________
> ?????????????? MSN Messenger:  http://messenger.msn.com/cn
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
>

--
  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

В списке pgsql-patches по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: clock_timestamp() and transaction_timestamp() function
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: clock_timestamp() and transaction_timestamp() function