Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fgYsD-0001FZ-W6 for pgsql-bugs@arkaria.postgresql.org; Fri, 20 Jul 2018 17:07:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fgYsC-0006DX-HR for pgsql-bugs@arkaria.postgresql.org; Fri, 20 Jul 2018 17:07:20 +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.89) (envelope-from ) id 1fgYsC-0006DQ-BY for pgsql-bugs@lists.postgresql.org; Fri, 20 Jul 2018 17:07:20 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fgYs9-0002Wq-Aq for pgsql-bugs@lists.postgresql.org; Fri, 20 Jul 2018 17:07:19 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w6KH7BB8023968; Fri, 20 Jul 2018 13:07:11 -0400 From: Tom Lane To: Ireneusz Pluta cc: Andres Freund , Andrew Gierth , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15287: postgres_fdw: the "WHERE date_trunc('day', dt) = 'YYYY-MM-DD' does not push to remote. In-reply-to: <9d6b978a-1aff-4f9e-03c6-0489836570d8@wp.pl> References: <153210427860.1404.15984608571673921883@wrigleys.postgresql.org> <20180720163945.exro5xgl7skq3kzo@alap3.anarazel.de> <9d6b978a-1aff-4f9e-03c6-0489836570d8@wp.pl> Comments: In-reply-to Ireneusz Pluta message dated "Fri, 20 Jul 2018 18:48:09 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <23966.1532106431.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 20 Jul 2018 13:07:11 -0400 Message-ID: <23967.1532106431@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Ireneusz Pluta writes: > W dniu 2018-07-20 o=C2=A018:39, Andres Freund pisze: >> You're probably going to have a higher likelihood of getting the bug >> fixed quickly if you'd include a full reproducer. > Sure, but RhodiumToad was so kind promising to follow up on this, so I s= kipped that chore :-). It may be a bug, but I'm afraid it's a can't-fix one, at least for the foreseeable future. postgres_fdw is correctly determining that the date_trunc function's input collation is being chosen on the basis of a defaultly-collated literal, and that makes it unsafe to ship. The situation is not different from the case of, say, 'foo'::text > 'bar'::text (ignoring the likelihood that that'd get const-folded before it got here). If that expression is evaluated locally, the result will depend on the local database's default collation; whereas if we send it for remote execution, the result will depend on the remote database's default collation, and could very well be different. In reality, date_trunc() pays no attention to its input collation; but postgres_fdw has no way to know that, so it can't safely ship this expression. If we had a way to know that the remote database's default collation acts the same as the local one's, we could use different and more forgiving rules about what can be shipped; but I'm not sure how we could know that reliably. (We could perhaps check that it was named the same, but in cross-platform situations that proves little.) Alternatively, if postgres_fdw could know which functions don't really pay attention to their input collation, it could skip this check for those functions. But that's not an easy thing to fix either. regards, tom lane