Re: CAST(integer_field AS character) truncates trailing zeros

From: "Richard Broersma" <richard(dot)broersma(at)gmail(dot)com>
To: "Warren Bell" <warren(at)clarksnutrition(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: CAST(integer_field AS character) truncates trailing zeros
Date: 2008-07-31 20:17:24
Message-ID: 396486430807311317y340ab863uf3c24b588ce7adfd@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Jul 31, 2008 at 1:03 PM, Warren Bell <warren(at)clarksnutrition(dot)com> wrote:
> I am trying to cast an int to a character. The int is the number 1000 it
> gets cast down to "1" and not "1000". How do I cast from int to character
> without loosing the trailing zeros?

Here is what I get when I try:

postgres=# select cast( cast( 1000 as integer ) as char );
bpchar
--------
1
(1 row)

postgres=# select cast( cast( 1000 as integer ) as char(10) );
bpchar
------------
1000
(1 row)

--
Regards,
Richard Broersma Jr.

Visit the Los Angeles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Robert Treat 2008-07-31 20:17:46 Re: Using PostGres general distribution
Previous Message Douglas McNaught 2008-07-31 20:16:33 Re: CAST(integer_field AS character) truncates trailing zeros