Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search archives
  Advanced Search

Re: [GENERAL] combining contents of two fields into a new field?


  • From: Jeff Hoffmann <jeff(at)remapcorp(dot)com>
  • To: "William J. Stotts" <wstotts(at)sonitrol(dot)net>
  • Cc: pgsql-general(at)postgreSQL(dot)org
  • Subject: Re: [GENERAL] combining contents of two fields into a new field?
  • Date: Mon, 22 Feb 1999 12:40:01 -0600
  • Message-id: <36D1A481.B1706BF9@remapcorp.com> <text/plain>

"William J. Stotts" wrote:
> 
> Hi folks,
> 
> Please excuse this question for it shows my ignorance;-)
> 
> I need to combine the contents of three different fields into a single
> field. I understand how to perform an update on a field with the contents
> of another field via a query like:
>  UPDATE dice_data SET dice_new_phone = dice_prefix
> 
> I need to update this field with a concatenation of three fields actually.
> What I am ignorant of is how to perform such an update. WOuld someone
> kindly guide me in how to perform such an update?
> 

if the fields are character data, you'd want to use the concatenate
operator "||".  the last i checked, you can't string a bunch of fields
together, so more than two fields is a PITA (you have to use a bunch of
parentheses to group things together).  there was talk of changing this,
but i forget what happened to it.

for example a phone number might be something like this:

update my_data set new_phone = (('(' || area_code) || ') ') || ((prefix
|| '-') || number);

(i hope i got the parentheses right, and i hope this helps.)

jeff



Home | Main Index | Thread Index

Privacy Policy | About PostgreSQL
Copyright © 1996 – 2012 PostgreSQL Global Development Group