Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 8DAA219F7A76 for ; Wed, 30 Nov 2011 21:10:40 -0400 (AST) Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RVvAZ-0005GO-TC for pgsql-bugs@postgresql.org; Thu, 01 Dec 2011 01:10:39 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id pB11AMhZ004162; Wed, 30 Nov 2011 20:10:22 -0500 (EST) To: Jeff Davis cc: pgsql-bugs@postgresql.org Subject: Re: possible bug seen with -DCLOBBER_CACHE_ALWAYS and changing GUCs In-reply-to: References: Comments: In-reply-to Jeff Davis message dated "Wed, 30 Nov 2011 13:59:17 -0800" Date: Wed, 30 Nov 2011 20:10:22 -0500 Message-ID: <4161.1322701822@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -3.1 (---) X-Archive-Number: 201111/212 X-Sequence-Number: 31807 Jeff Davis writes: > SQL: > set datestyle to postgres,us; > prepare stmt as select '02-01-2011'::date::text; > execute stmt; > set datestyle to postgres,euro; > execute stmt; > deallocate stmt; > The results I get with normal debug compilation are: > SET > PREPARE > text > ------------ > 02-01-2011 > (1 row) > SET > text > ------------ > 01-02-2011 > (1 row) > DEALLOCATE The result of parse analysis for that query is a stored date constant (in a Const node) with a cast-to-text on top of it. The system is aware that cast-date-to-text isn't immutable, so it doesn't try to fold the cast operation. When you execute the query, it displays the date constant using the now-current datestyle. > But with -DCLOBBER_CACHE_ALWAYS and -DRELCACHE_FORCE_RELEASE, I get: > SET > PREPARE > text > ------------ > 02-01-2011 > (1 row) > SET > text > ------------ > 02-01-2011 > (1 row) > DEALLOCATE > Which one of those results is correct? I believe what is happening in the second case is that the query is getting re-parse-analyzed, from scratch, and since now datestyle is different (DMY not MDY), the date literal gets interpreted differently. You could argue it either way as to which result is "more correct", but I doubt we're going to try to do something about that. Best advice is to avoid ambiguous input, or if you can't, at least avoid flipping your datestyle on the fly. regards, tom lane