Re: UPDATE the field of a table with fields from another

From: Balvie <ener(at)ibb(dot)nl>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: UPDATE the field of a table with fields from another
Date: 2006-10-16 13:46:27
Message-ID: 45338D33.604@ibb.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice


> Balvie <ener(at)ibb(dot)nl> writes:
>
>> UPDATE b1_naam
>> SET telnr = t.telnr
>> FROM b1_telco as t
>> WHERE
>> b1_naam.relcode = b1_telco.relcode AND
>>
> ^^^^^^^^ should be t
>
>> b1_naam.naam like 'Bakke%';
>>
>
> Less-obsolete versions of Postgres would have warned you about this,
> or even reported it as an error.
>
> regards, tom lane
>
>
Thanks Tom,

I did try a lot myself, taking different appraoches and structures and
different queries. Together with your tip's I changed it finally this
morning to:

update b1_telco
set telnr = n.telnr
from
b1_telco as t inner join b1_naam as n on t.relcode = n.relcode
where
n.naam like 'Bakk%';

and it still has flaws.

Observations:
a. *All* records were affected instead of those specified in the
where-clause.
b. the value to which the field is set (set telnr = n.telnr), is the
same for all affected records. My intention was to copy the
corresponding fields.
c. there are no sql errors: Query returned successfully: 10246 rows
affected, 422 ms execution time.

I'd very much like to hear the response(s).

Balvie

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Ray Stell 2006-10-16 14:34:14 pgfoundry.org cksums?
Previous Message Michael Fuhr 2006-10-16 13:41:24 Re: Using host variables -- segmentation fault