agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFrom: Steve Crawford <scrawford@pinpointresearch.com>
To: ng <pipelines@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: PGsql function timestamp issue
Date: Thu, 29 May 2014 14:13:02 -0700
Message-ID: <5387A2DE.20207@pinpointresearch.com> (raw)
In-Reply-To: <CAAQKod115J-w7hiJ+rG8kn2FVqW51+ZVJsVpELNcU1Q4cw69dQ@mail.gmail.com>
References: <CAAQKod115J-w7hiJ+rG8kn2FVqW51+ZVJsVpELNcU1Q4cw69dQ@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>
On 05/29/2014 01:46 PM, ng wrote:
>
> create or replace function dw.fx_nish()
> returns text
> language plpgsql
> as
> $$
> declare
> x timestamp with time zone;
> y timestamp with time zone;
> begin
> x:= current_timestamp;
> perform pg_sleep(5);
> y:= current_timestamp;
> if x=y then
> return 'SAME';
> else
> return 'DIFFERENT';
> end if;
>
> end;
> $$
>
>
> select dw.fx_nish()
> This give me 'SAME'
>
> Any work around for this?
No and yes.
The value of current_timestamp will remain constant throughout a
transaction so the function is returning the expected result.
You can use timeofday() but since that returns a string representing
wall-clock time and does increment within a transaction. To get a
timestamptz you will need to cast it: timeofday()::timestamptz
Cheers,
Steve
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
view thread (5+ messages) latest in thread
Message-ID: <5387A2DE.20207@pinpointresearch.com>
Permalink: ../5387A2DE.20207@pinpointresearch.com/
Also on: postgresql.org/message-id/5387A2DE.20207@pinpointresearch.com
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: scrawford@pinpointresearch.com, pipelines@gmail.com
Subject: Re: PGsql function timestamp issue
In-Reply-To: <5387A2DE.20207@pinpointresearch.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox