Re: SELECT CAST(123 AS char) -> 1 - Mailing list pgsql-general

From Richard Huxton
Subject Re: SELECT CAST(123 AS char) -> 1
Date
Msg-id 47B3367D.6050808@archonet.com
Whole thread Raw
In response to Re: SELECT CAST(123 AS char) -> 1  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Tom Lane wrote:
> Richard Huxton <dev@archonet.com> writes:
>> [ proof that cast(123 as char) actually produces varchar in mysql ]
>
> Egad.  I wonder if they think this is a feature?

Well, presumably its what all the other "convenient" (for Ken's
particular problem) databases do. The only alternative I could see would
be to use a varchar while casting values and then check lengths at the
end before re-casting to e.g. char(6).

Interestingly, it must have some lookup table mapping numeric types to
lengths of varchar because a standard int gives you varchar(11) whereas
an expression that pushes you beyond 32 bits gives varchar(32) and a
tinyint gives you varchar(4). Clearly some thought has gone into this.

--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: SELECT CAST(123 AS char) -> 1
Next
From: Michael Fuhr
Date:
Subject: Re: Order of SUBSTR and UPPER in statement