Re: Casting from varchar to numeric

From: Tom Ansley <tansley(at)law(dot)du(dot)edu>
To: tansley(at)mail(dot)law(dot)du(dot)edu, pgsql-novice(at)postgresql(dot)org
Subject: Re: Casting from varchar to numeric
Date: 2002-05-16 17:18:33
Message-ID: 200205161118.33795.tansley@law.du.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi all,

ok...so the solution I currently have is to convert the varchar(10) into a
numeric value and then convert it back into a varchar but with all the bits
added. This is my current code

to_char( to_number(hotel.main_phone, '9999999999') ,'(999)999-9999')

The problem with this is that I am getting a space between the first number
and the first bracket so it looks something like this....

( 999)999-9999

I have tried to get rid of the space using the MI template pattern but nothing
seems to work.

Does anybody have any ideas as to what is going wrong.

Cheers

Tom

On Thursday 16 May 2002 09:48 am, Tom Ansley wrote:
> Hi list,
>
> Is there a way of casting from a varchar to a numeric type?
>
> My problem consists of a varchar(10) that are all numeric. They are
> telephone numbers and I want to convert them during a select statement to
> (XXX) XXX-XXXX
>
> Anybody have any ideas?
>
> Thanks
>
> Tom
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Joel Burton 2002-05-16 17:47:39 Re: Casting from varchar to numeric
Previous Message gerry.smit 2002-05-16 17:17:35 Re: Trouble with index in 7.1