Re: cast numeric to char: SOLVED

From: "Johnson, Shaunn" <SJohnson6(at)bcbsm(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: cast numeric to char: SOLVED
Date: 2002-10-28 15:16:09
Message-ID: 73309C2FDD95D11192E60008C7B1D5BB04C74116@snt452.corp.bcbsm.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

--never mind. i think i have it:

[snip example]

testdb=> select to_char(i_paid,'0000009.99') from t_table limit 1;
to_char
-------------
0000000.00
(1 row)

[/snip example]

--thanks all!

-X


-----Original Message-----
From: Johnson, Shaunn
Sent: Monday, October 28, 2002 10:13 AM
To: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] cast numeric to char

--thanks for the reply

--but, at the same time, i seem to lose my decimal values.
--should that happen? how can i keep those values at the
--end?

-X

-----Original Message-----
From: Ian Harding [ mailto:ianh(at)tpchd(dot)org <mailto:ianh(at)tpchd(dot)org> ]

Yes, you cannot cast a numeric to character, but there is a function called
to_char() that will help.

Something like:

planning=# select to_char(4, '0000009');
to_char
----------
0000004

The only annoying thing is that it seems to put a blank in front of the
string, I am not sure why. You will probably want to trim() the results.

Ian A. Harding
Programmer/Analyst II
Tacoma-Pierce County Health Department
(253) 798-3549
iharding(at)tpchd(dot)org

<This Space Intentionally Left Blank>

Howdy:

Running PostgreSQL 7.2.1 -

I'm trying to cast a numeric field to character, but I
am getting errors saying that it can not be done.

[snip errors]

testdb=> select lpad(i_pd::char,7,'0') from t_table limit 1;
ERROR: Cannot cast type 'numeric' to 'character'

[/snip error]

Is it that I *can not* cast numeric into character value or
or do I need some new methodology of doing this?

Thanks!

-X

Browse pgsql-general by date

  From Date Subject
Next Message Doug McNaught 2002-10-28 15:16:40 Re: pb with insertion
Previous Message Johnson, Shaunn 2002-10-28 15:13:02 Re: cast numeric to char