473,659 Members | 2,929 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

update field using substrings of another field


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(fnumb er from 1 for 3) || ') ' ||
substring(fnumb er from 4 for 3) || '-' || substring(fnumb er 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

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 11 '05 #1
3 2833
"Dave [Hawk-Systems]" <da**@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(fnumb er from 1 for 3) || ') ' ||
substring(fnumb er from 4 for 3) || '-' || substring(fnumb er 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 ma*******@postg resql.org

Nov 11 '05 #2
Doug McNaught <do**@mcnaught. org> writes:
"Dave [Hawk-Systems]" <da**@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"
You could do it fairly easily with a trigger.


Or consider plan B: why bother to actually store "number" at all,
if it is trivially computable from "fnumber"?

You could make a view that includes "number" as a derived column,
if you have apps that insist on seeing it as an ordinary-looking
column in the select result.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 11 '05 #3
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]" <da**@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(fnumb er from 1 for 3) || ') ' ||
substring(fnu mber from 4 for 3) || '-' || substring(fnumb er 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 ma*******@postg resql.org


--
Andreas Fromm

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


---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 11 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6308
by: rrh | last post by:
I am trying to update a field in one table with data from another table. The problem I'm running into is I need to base the update on a range of data in the 2nd table. Table 1 has: date field new field table 2 has: key field (autonumber)
4
26187
by: N. Graves | last post by:
Hello... thank you for your time. I have a form that has a List box of equipotent records and a sub form that will show the data of the equipment select from the list box. Is it possible to make a change in the name field in the details, then refresh the list box with new name? Please help and thanks!
8
3714
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: "Date","P1","P2","P3","P4","P5","P6","P7","P8","P9","P10","P11","P12","P13","P14","P15","P16","P17","P18","P19","P20","P21" 1/1/2005,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21 1/2/2005,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22
9
1800
by: C3 | last post by:
I have to process some data in C that is given to me as a char * array. I have a fairly large number of substrings (well, they're not actually printable, but let's treat them as strings) that I have to search for in the data. I need to keep a count of how often each of these substrings occurs in my original data and then print it out at the end. This is a fairly mundane task, but since I have so many substrings, it's a pain having to...
13
2644
by: Lyners | last post by:
I have a web page writen in ASP.NET that contains some javascript so that when a user presses a button, or edits a certain field in a datagrid, another cell in the datagrid is filled with a value. My probelm.... when I have the user press the update button (which does a post back that loops through the datagrid and updates a database) the field/cell that is filled by the javascript appears to be blank in my update code, even though I can...
2
3101
by: Miro | last post by:
I will ask the question first then fumble thru trying to explain myself so i dont waste too much of your time. Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an index - i havnt tested the index yet ) so you can use an .UPDATE( dataTable ) on the data adapter. Otherwise you will get an exception error. Is this statement true? ---- Now me fumbling thru
19
4159
by: eric.nave | last post by:
this is a slight change to a fequently asked question around here. I have a table which contains a "sortorder" column where a user can specify some arbitrary order for records to be displayed in. Users have sometimes ordered records the way we used to number lines in a BASIC program (10,20,30, etc.). I'd like to do an update query and fix this so that every record is in sequential order. I found an example in this newsgroup of how to...
2
1980
by: CollierC | last post by:
I need to write a query that manipulates a name field from "firstname lastname" to "lastname, firstname". I have read multiple solutions to split firstname and lastname to separate fields, unfortunately I haven't found anyting on manipulating substrings within the same field. Can this be done?
4
7770
by: hapnendad | last post by:
In the question statement below Field names are in and variables are in (). All fields referenced are in what I have named the ‘PAR’ Table. Using MS Access 2003, I am working on a project management database and have reached the point where I need to develop a way for managers to re-assign responsibility for all active projects to another of his/her resources. The Field names for the different managers associated with each project are: ...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8337
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8748
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8531
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.