update field using substrings of another field

From: "Dave [Hawk-Systems]" <dave(at)hawk-systems(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: update field using substrings of another field
Date: 2003-09-16 13:58:25
Message-ID: DBEIKNMKGOBGNDHAAKGNEEBDEKAC.dave@hawk-systems.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


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?

thanks

Dave

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2003-09-16 14:08:24 Re: date_part('timezone_hour')
Previous Message Lamar Owen 2003-09-16 13:52:59 Re: State of Beta 2