Re: BUG #5028: CASE returns ELSE value always when type is"char"

From: Sam Mason <sam(at)samason(dot)me(dot)uk>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #5028: CASE returns ELSE value always when type is"char"
Date: 2009-09-02 15:55:31
Message-ID: 20090902155531.GS5407@samason.me.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Wed, Sep 02, 2009 at 03:50:05PM +0100, Greg Stark wrote:
> Perhaps we should stop thinking of "unknown" as, er, "unknown" and
> think of it as "text literal". A text literal has implicit casts to
> every data type but a normal text string has to be explicitly cast.

How does that help things? You seem to be keeping the semantics and
only changing the name, when it's the semantics that you seem to be
complaining about.

I'm pretty sure it's correct to treat it as "unknown", other
type-systems do this and it all works well. The thing that makes things
ambiguous is the ad-hoc polymorphism that exists in function calls
and operators. With PG's type system you know almost nothing about
any types involved in an arbitrary expression, operators are better
than functions (given the types of the arguments you know the return
type, with default parameters even this knowledge doesn't exist with
functions) but still leave things far too open to have any rigor without
spelling out types in full everywhere. For example:

CREATE FUNCTION add(int,int) RETURNS int LANGUAGE sql
AS $$ SELECT $1 + $2; $$;

CREATE FUNCTION add(int,int,int DEFAULT NULL) RETURNS text LANGUAGE sql
AS $$ SELECT ($1 + $2)::text; $$;

What type should it attribute to the result of:

SELECT add(1,2);

In fact it doesn't seem to want to play ball at all. Even given the
apparently unambiguous:

SELECT 1+add(1,2);
or
SELECT 'hi'||add(1,2);

It doesn't get anywhere. No need for "text 'hi'" in the second one
because || isn't defined for values of integer type.

--
Sam http://samason.me.uk/

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Robert Haas 2009-09-02 16:36:00 Re: BUG #5028: CASE returns ELSE value always when type is"char"
Previous Message Tom Lane 2009-09-02 15:36:34 Re: BUG #5025: Aggregate function with subquery in 8.3 and 8.4.