Re: Casting from varchar to numeric

From: "Adam Erickson" <adamre(at)cox(dot)net>
To: "Pgsql-Novice" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Casting from varchar to numeric
Date: 2002-05-16 16:38:21
Message-ID: ALEKKHACBIAEBNBPFKPCOEJDCOAA.adamre@cox.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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...;

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message gerry.smit 2002-05-16 17:13:22 Re: Answering my own question
Previous Message gerry.smit 2002-05-16 16:11:12 Re: Answering my own question