Re: UPDATE the field of a table with fields from another - Mailing list pgsql-novice

From Balvie
Subject Re: UPDATE the field of a table with fields from another
Date
Msg-id 45338D33.604@ibb.nl
Whole thread Raw
In response to Re: UPDATE the field of a table with fields from another table  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-novice
> Balvie <ener@ibb.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


pgsql-novice by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: Using host variables -- segmentation fault
Next
From: Ray Stell
Date:
Subject: pgfoundry.org cksums?