Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Wq7dR-0007ZG-Lv for pgsql-sql@arkaria.postgresql.org; Thu, 29 May 2014 21:13:13 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Wq7dQ-0002WN-T1 for pgsql-sql@arkaria.postgresql.org; Thu, 29 May 2014 21:13:12 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Wq7dP-0002WE-PP for pgsql-sql@postgresql.org; Thu, 29 May 2014 21:13:11 +0000 Received: from cerberus.pinpointresearch.com ([66.7.238.130] helo=polaris.pinpointresearch.com) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Wq7dH-0002MV-JG for pgsql-sql@postgresql.org; Thu, 29 May 2014 21:13:09 +0000 Received: from [192.168.1.179] (betelgeuse.pinpointresearch.com [192.168.1.179]) by polaris.pinpointresearch.com (Postfix) with ESMTP id A7BD4E00EC82; Thu, 29 May 2014 14:13:02 -0700 (PDT) Message-ID: <5387A2DE.20207@pinpointresearch.com> Date: Thu, 29 May 2014 14:13:02 -0700 From: Steve Crawford User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: ng , pgsql-sql@postgresql.org Subject: Re: PGsql function timestamp issue References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org 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