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

From: Jeff Hoffmann <jeff(at)remapcorp(dot)com>
To: "William J(dot) 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: 1999-02-22 18:40:01
Message-ID: 36D1A481.B1706BF9@remapcorp.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Davis 1999-02-22 18:42:55 Transaction logging
Previous Message Ross J. Reedstrom 1999-02-22 18:23:41 Re: [GENERAL] combining contents of two fields into a new field?