Re: SELECT CAST(123 AS char) -> 1

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SELECT CAST(123 AS char) -> 1
Date: 2008-02-16 19:05:41
Message-ID: 20080216110308.T93259@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, 16 Feb 2008, Tom Lane wrote:

> Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)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:

Yeah. Although, IIRC, it was one of the options he mentioned as being
better than getting the first character but not what he really wanted.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrej Ricnik-Bay 2008-02-16 19:47:55 Re: Are indexes blown?
Previous Message Ken Johanson 2008-02-16 17:04:36 Re: Strict-typing benefits/costs