Re: Casting from varchar to numeric - Mailing list pgsql-novice

From Josh Berkus
Subject Re: Casting from varchar to numeric
Date
Msg-id web-1461767@davinci.ethosmedia.com
Whole thread Raw
In response to Casting from varchar to numeric  (Tom Ansley <tansley@law.du.edu>)
List pgsql-novice
Tom,

> 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?

Well, first off, you need to know the PostgreSQL conversion functions.
 See the online documentation:  Functions and Operators --> Formatting
Functions.

Second, if you check Roberto Mello's PL/pgSQL cookbook, you'll notice
that I posted a set of functions which auto-format phone numbers to US
spec.
http://www.brasileiro.net/postgres/cookbook/

It's under "String Manipulation Functions".

-Josh Berkus

pgsql-novice by date:

Previous
From: "Adam Erickson"
Date:
Subject: Re: Answering my own question
Next
From: gerry.smit@lombard.ca
Date:
Subject: Re: Answering my own question