Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 85180B5DBE8 for ; Wed, 25 May 2011 09:21:50 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 31680-08 for ; Wed, 25 May 2011 12:21:43 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og115.obsmtp.com (exprod7og115.obsmtp.com [64.18.2.217]) by mail.postgresql.org (Postfix) with ESMTP id 8E7D5B5DBE5 for ; Wed, 25 May 2011 09:21:42 -0300 (ADT) Received: from mail-ew0-f42.google.com ([209.85.215.42]) (using TLSv1) by exprod7ob115.postini.com ([64.18.6.12]) with SMTP ID DSNKTdz0VkSqnyCPFuiE6r9hSFL2sr5Mjmq3@postini.com; Wed, 25 May 2011 05:21:43 PDT Received: by ewy2 with SMTP id 2so2948045ewy.15 for ; Wed, 25 May 2011 05:21:40 -0700 (PDT) Received: by 10.14.187.138 with SMTP id y10mr300374eem.145.1306326100611; Wed, 25 May 2011 05:21:40 -0700 (PDT) Received: from [192.168.1.183] (dsl-hkibrasgw2-ff7ac300-240.dhcp.inet.fi [88.195.122.240]) by mx.google.com with ESMTPS id y8sm3729733eeh.0.2011.05.25.05.21.38 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 25 May 2011 05:21:39 -0700 (PDT) Message-ID: <4DDCF44D.2020604@enterprisedb.com> Date: Wed, 25 May 2011 15:21:33 +0300 From: Heikki Linnakangas User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; fi-FI; rv:1.9.1.16) Gecko/20110505 Icedove/3.0.11 MIME-Version: 1.0 To: PostgreSQL-development Subject: Re: Nested CASE-WHEN scoping References: <4DDCEEB8.50602@enterprisedb.com> In-Reply-To: <4DDCEEB8.50602@enterprisedb.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201105/1235 X-Sequence-Number: 188269 On 25.05.2011 14:57, Heikki Linnakangas wrote: > Here's a bit contrived example: > > CREATE FUNCTION evileq (timestamptz, int4) returns boolean AS $$ > SELECT case $2 WHEN length($1::text) THEN true ELSE false END; > $$ language sql; > CREATE OPERATOR = (procedure = evileq, leftarg = timestamptz, rightarg = > int4); > > postgres=# SELECT now() = 29, CASE now() WHEN 29 THEN 'foo' ELSE 'bar' END; > ?column? | case > ----------+------ > t | bar > (1 row) > > Direct call to the operator, "now () = 29" returns true, but when used > in CASE-WHEN, which implicitly does the same comparison, the result is > false. Admittedly that's pretty far-fetched, but nevertheless it's a bug. I should add that this works fine if the function is not an SQL function that gets inlined. But inlining is desirable, we don't want to give up on that, and inhibiting it in that case would need some extra bookkeeping anyway. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com