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

From Adam Erickson
Subject Re: Casting from varchar to numeric
Date
Msg-id ALEKKHACBIAEBNBPFKPCOEJDCOAA.adamre@cox.net
Whole thread Raw
In response to Casting from varchar to numeric  (Tom Ansley <tansley@law.du.edu>)
List pgsql-novice
> 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

Would this work?

CREATE FUNCTION format_us_phone(varchar)
RETURNS varchar AS '
BEGIN;
SELECT "(" || SUBSTR($1,0,3) || ")" || SUBSTR($1,3,3) || "-" ||
SUBSTR($1,6,4);
END; ' LANGUAGE 'sql';

then..

SELECT format_us_phone(phonefield) FROM...;


pgsql-novice by date:

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