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

From Tom Lane
Subject Re: SELECT CAST(123 AS char) -> 1
Date
Msg-id 19594.1203176844@sss.pgh.pa.us
Whole thread Raw
In response to Re: SELECT CAST(123 AS char) -> 1  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
Responses Re: SELECT CAST(123 AS char) -> 1
Re: SELECT CAST(123 AS char) -> 1
List pgsql-general
Stephan Szabo <sszabo@megazone.bigpanda.com> writes:
> On Tue, 12 Feb 2008, Tom Lane wrote:
>> Also, section 6.10 <cast specification> defines an explicit cast to
>> a fixed-length string type as truncating or padding to the target
>> length (LTD):

> Are you sure that's the correct section to be using? Isn't that 6.10
> General Rules 5c which is if the source type is a fixed or variable
> length character string? Wouldn't the correct place for an int->char
> conversion be 5a or am I misreading it?

Hm, good point, so really we ought to have a separate casting path for
numeric types to char(n).  However, this section still doesn't offer
any support for the OP's desire to auto-size the result; it says
that you get an error if the result doesn't fit in the declared
length:

>              iv) Otherwise, an exception condition is raised: data exception-
>                  string data, right truncation.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Timestamp indexes (why ">" or "between" does not use index?)
Next
From: Ken Johanson
Date:
Subject: Re: SELECT CAST(123 AS char) -> 1