| From: | Michael A Nachbaur <mike(at)nachbaur(dot)com> |
|---|---|
| To: | Yasir Malik <ymalik(at)cs(dot)stevens-tech(dot)edu>, pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: Datatype conversion help |
| Date: | 2003-07-08 20:26:23 |
| Message-ID: | 200307081326.23538.mike@nachbaur.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
You want to use:
nachbaur=# select to_char(5, '00');
to_char
---------
05
(1 row)
By using "0", you indicate you want leading zeros. See
http://www.postgresql.org/docs/view.php?version=7.3&idoc=1&file=functions-formatting.html
for more information.
On Tuesday 08 July 2003 01:07 pm, Yasir Malik wrote:
> Suppose I have an integer between 0 and 99 and I want to covert it to
> string, and pad leading zeros if neccessary. For example,
> 1 => 01
> 10 => 10
>
> I've tried to_char(in_val, '99'), and that returns a string that is two
> charecters, but there isn't a leading zero incase I have the number 2 as
> input. Any ideas? Thanks.
> Yasir
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings
--
/* Michael A. Nachbaur <mike(at)nachbaur(dot)com>
* http://nachbaur.com/pgpkey.asc
*/
"Oh no, not again."
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Yasir Malik | 2003-07-08 20:28:48 | Re: Datatype conversion help |
| Previous Message | Yasir Malik | 2003-07-08 20:07:05 | Datatype conversion help |