pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>
Subject: Re: Nested CASE-WHEN scoping
Date: Wed, 25 May 2011 15:21:33 +0300
Message-ID: <4DDCF44D.2020604@enterprisedb.com> (raw)
In-Reply-To: <4DDCEEB8.50602@enterprisedb.com>
References: <4DDCEEB8.50602@enterprisedb.com>

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



view thread (15+ messages)  latest in thread

Message-ID: <4DDCF44D.2020604@enterprisedb.com>
Permalink:  ../4DDCF44D.2020604@enterprisedb.com/
Also on:    postgresql.org/message-id/4DDCF44D.2020604@enterprisedb.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: heikki.linnakangas@enterprisedb.com
  Subject: Re: Nested CASE-WHEN scoping
  In-Reply-To: <4DDCF44D.2020604@enterprisedb.com>
  References: <4DDCEEB8.50602@enterprisedb.com> <4DDCF44D.2020604@enterprisedb.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox