From: | bricklen <bricklen(at)gmail(dot)com> |
---|---|
To: | Steve Crawford <scrawford(at)pinpointresearch(dot)com> |
Cc: | ng <pipelines(at)gmail(dot)com>, "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: PGsql function timestamp issue |
Date: | 2014-05-29 22:00:05 |
Message-ID: | CAGrpgQ9U86N0xQYYx7bV3Ct_z_ehDBuz5D8H4a_Kmy1gMOiq5w@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Thu, May 29, 2014 at 2:13 PM, Steve Crawford <
scrawford(at)pinpointresearch(dot)com> wrote:
> 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
>
Or use clock_timestamp()
From | Date | Subject | |
---|---|---|---|
Next Message | David G Johnston | 2014-06-09 13:36:13 | Re: Parameterized Query |
Previous Message | Steve Crawford | 2014-05-29 21:13:02 | Re: PGsql function timestamp issue |