Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1a786V-0007bG-1G for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Dec 2015 20:46:19 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1a786U-0001wg-Jm for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Dec 2015 20:46:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1a77H2-0005h8-52 for pgsql-bugs@postgresql.org; Thu, 10 Dec 2015 19:53:08 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1a77Gz-0000Hg-1V for pgsql-bugs@postgresql.org; Thu, 10 Dec 2015 19:53:06 +0000 MIME-Version: 1.0 Subject: BUG #13812: 'now' acting differently than now() in function To: pgsql-bugs@postgresql.org From: darin@darinhoward.com Date: Thu, 10 Dec 2015 19:52:22 +0000 Message-ID: <20151210195222.2683.3870@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.2 (-) Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 13812 Logged by: Darin Howard Email address: darin@darinhoward.com PostgreSQL version: 9.4.5 Operating system: Linux Description: Running into an issue where now() behaves different than 'now' when used in a function in Postgres. drop table if exists test_date_bug; CREATE TABLE test_date_bug ( id serial NOT NULL, date1 timestamp with time zone NOT NULL DEFAULT current_timestamp, date2 timestamp with time zone NOT NULL DEFAULT 'infinity' ) WITH ( OIDS=FALSE ); drop function if exists test_date_bug_function(id_param bigint); CREATE OR REPLACE FUNCTION test_date_bug_function(id_param bigint) RETURNS void AS $$ BEGIN UPDATE test_date_bug SET date2 = 'now' WHERE id = id_param; END; $$ LANGUAGE 'plpgsql' VOLATILE SECURITY DEFINER SET search_path = public, pg_temp; insert into test_date_bug DEFAULT VALUES; insert into test_date_bug DEFAULT VALUES; insert into test_date_bug DEFAULT VALUES; select 1 from test_date_bug_function(1); wait a couple seconds select 1 from test_date_bug_function(2); Results: select * from test_date_bug; id | date1 | date2 ----+-------------------------------+------------------------------- 3 | 2015-12-10 12:42:01.931554-06 | infinity 1 | 2015-12-10 12:42:01.334465-06 | 2015-12-10 12:42:09.491183-06 2 | 2015-12-10 12:42:01.335665-06 | 2015-12-10 12:42:09.491183-06 (3 rows) I would not expect the date2 on row 2 to be the same date2 as row 1. Replacing UPDATE test_date_bug SET date2 = 'now' WHERE id = id_param; With UPDATE test_date_bug SET date2 = now() WHERE id = id_param; Sets new date as I would expect: select * from test_date_bug; id | date1 | date2 ----+-------------------------------+------------------------------- 3 | 2015-12-10 12:43:29.480242-06 | infinity 1 | 2015-12-10 12:43:28.451195-06 | 2015-12-10 12:43:38.496625-06 2 | 2015-12-10 12:43:28.451786-06 | 2015-12-10 12:43:43.447715-06 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs