Re: update field using substrings of another field - Mailing list pgsql-general

From Doug McNaught
Subject Re: update field using substrings of another field
Date
Msg-id m3isnsrff2.fsf@varsoon.wireboard.com
Whole thread Raw
In response to update field using substrings of another field  ("Dave [Hawk-Systems]" <dave@hawk-systems.com>)
Responses Re: update field using substrings of another field  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
"Dave [Hawk-Systems]" <dave@hawk-systems.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

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: date_part('timezone_hour')
Next
From: "scott.marlowe"
Date:
Subject: Re: CONCAT function