Re: BUG #5028: CASE returns ELSE value always when type is"char" - Mailing list pgsql-bugs

From Kevin Grittner
Subject Re: BUG #5028: CASE returns ELSE value always when type is"char"
Date
Msg-id 4A9E9066020000250002A962@gw.wicourts.gov
Whole thread Raw
In response to Re: BUG #5028: CASE returns ELSE value always when type is"char"  (Sam Mason <sam@samason.me.uk>)
List pgsql-bugs
Sam Mason <sam@samason.me.uk> wrote:
> On Wed, Sep 02, 2009 at 02:59:54PM -0500, Kevin Grittner wrote:
>> Sam Mason <sam@samason.me.uk> wrote:
>> >   CREATE VIEW v (c) AS
>> >     SELECT NULL;
>> >
>> > PG allows it, but the resulting view seems somewhat unusable.
>>
>> I'm not sure whether the only place the standard doesn't require a
>> cast is on assignment, but this is one place that the standard
>> clearly does require a cast, and I'm all for that.
>
> I'm probably missing something obvious again, but where does it say
> that?  Bear in mind that my simple NULL could be an arbitrarily
> complex expression, I've just chosen a simple NULL for pedagogic
> reasons.
>
> I can only see a requirement that the chosen type must be
> compatible.  That seems to leave it open to arbitrarily choosing any
> type in this case.

I'll look.  On reflection, I based that statement on the fact that our
SQL parser requires it, and it was largely created by scanning in the
SQL syntax rules, using OCR on the image, and sed to format them for
ANTLR.  That doesn't guarantee that we didn't add that particular
requirement for the sake of our own sanity some time later.  I doubt I
can get to looking through the standard for it today, though.

By the way, the case of a bare NULL literal is potentially very
different from a complex expression which might resolve to NULL.  The
latter would generally have some result type which could be determined
even in tha absence of an actual value.  For example, a null-capable
column clearly has a type which can be determined.

-Kevin

pgsql-bugs by date:

Previous
From: Jaime Casanova
Date:
Subject: Re: BUG #5030: Problem on "RETURN QUERY EXECUTE" when a column is dropped from a table
Next
From: "Kevin Grittner"
Date:
Subject: Re: BUG #5028: CASE returns ELSE value always when type is"char"