Re: update field using substrings of another field

From: Andreas Fromm <Andreas(dot)Fromm(at)physik(dot)uni-erlangen(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: update field using substrings of another field
Date: 2003-09-16 14:47:48
Message-ID: 3F672294.8070201@physik.uni-erlangen.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Wouldn't it be the correct way to do such things just on retrieve of the
data, i.e. to implement the formatted output on the appication layer, or
maybe via a View, so that you don't save the data twice?

Doug McNaught wrote:

>"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
>
>---------------------------(end of broadcast)---------------------------
>TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>
>

--
Andreas Fromm

-----------------------------
Drink wet cement...
... and get stoned

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Lamar Owen 2003-09-16 15:04:54 Re: State of Beta 2
Previous Message Edwin Quijada 2003-09-16 14:44:16 Re: 4D to PostgreSQL tools