Re: BUG #18594: CASE WHEN ELSE failing to return the expected output when the same colum is used in WHEN and ELSE

From: Chris BSomething <xpusostomos(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, PostgreSQL Bug List <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #18594: CASE WHEN ELSE failing to return the expected output when the same colum is used in WHEN and ELSE
Date: 2025-02-19 12:50:22
Message-ID: CADrHaBFq+gK8DVpbvh-M2LVuvLu1JHz_rkKXirWCwNDZBhUUFg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, 18 Feb 2025 at 10:12, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Yeah. We document somewhere that the contents of a literal string are
> *not* considered while deciding what type it should be taken as; thus,
> the possibility of a casting failure is not part of the rules.
>

The length of a literal is not strictly speaking its "contents". One could
for example, have its type as varchar(x) where x is its length. And then
not have implicit typecasts from varchar(x) to varchar( < x).

> I think such a rule would be pretty dangerous, even if we could
> implement it easily. As an example, if you entered something you
> meant as a timestamp, but you fat-fingered the punctuation or
> something, it'd likely fall back to being considered just "text",
>

I don't get that, I thought timestamps have to be preceded by "TIMESTAMP".

potentially silently changing the semantics of the expression. We had

> a lot of trouble with that sort of behavior back when the system had a
> lot of implicit casts to text. We got rid of (most of) those in 8.3
> or thereabouts, and it made the semantics generally a lot safer.

So... you solved that, it sounds like.

And yet this super dangerous behavior which could sit dormant and
undiscovered in a view in a large computer system, doesn't bother anyone?
OK, whatever.

Chris

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2025-02-19 13:46:14 Re: BUG #18594: CASE WHEN ELSE failing to return the expected output when the same colum is used in WHEN and ELSE
Previous Message Matthias Apitz 2025-02-19 10:00:31 Re: BUG #18817: Security Bug Report: Plaintext Password Exposure in Logs