Re: update field using substrings of another field

From: Doug McNaught <doug(at)mcnaught(dot)org>
To: "Dave [Hawk-Systems]" <dave(at)hawk-systems(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: update field using substrings of another field
Date: 2003-09-16 14:12:01
Message-ID: m3isnsrff2.fsf@varsoon.wireboard.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Dave [Hawk-Systems]" <dave(at)hawk-systems(dot)com> writes:

> Have a table with fnumber and number, both text
> fnumber is a phone number, format "8005551212"
> number needs to be the same number but in the format "(800) 555-1212"
>
> we currently run the following each time the list is updated;
> update pnums set number='(' || substring(fnumber from 1 for 3) || ') ' ||
> substring(fnumber from 4 for 3) || '-' || substring(fnumber from 7 for 4);
>
> is there a way to statically set that number field so that it always
> equals the fnumber in that format, or automatically updates itself
> when the fnumber field is changed?

You could do it fairly easily with a trigger.

-Doug

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message scott.marlowe 2003-09-16 14:13:19 Re: CONCAT function
Previous Message Tom Lane 2003-09-16 14:08:24 Re: date_part('timezone_hour')