Re: how to write correctly this update ?

From: Rob Sargent <robjsargent(at)gmail(dot)com>
To: Pierre Couderc <pierre(at)couderc(dot)eu>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: how to write correctly this update ?
Date: 2019-05-22 13:19:28
Message-ID: 7D3837A3-CFEC-4D65-AC70-12193C1124D2@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Don’t use the alias on the column(s) being set.
This passed the parser:
UPDATE personnes T1 SET nom_naiss=T1.nom FROM personnes T2, personnes T3
WHERE T1.id=T2.id_mere AND T2.id_pere=T3.id AND T1.nom != T3.nom;

(I have no data in my table so I can’t confirm the logic. You seem to want to update mother’s maiden name if her current (sur)name doesn’t match that of the father of (one of?) her children? That might be a serious leap of faith.)

> On May 22, 2019, at 6:43 AM, Pierre Couderc <pierre(at)couderc(dot)eu> wrote:
>
> I have tried many ways to update a table :
>
> UPDATE personnes T1 SET T1.nom_naiss=T1.nom FROM personnes T2, personnes T3
> WHERE ....;
>
>
> UPDATE personnes T1 SET T1.nom_naiss=T1.nom FROM personnes T1, personnes T2, personnes T3
> WHERE ..;
>
>
> In my case , where clause is : WHERE T1.id=T2.id_mere AND T2.id_pere=T3.id AND T1.nom != T3.nom;
>
> Thanks.
>
> PC
>
>
>
>
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Durumdara 2019-05-22 13:43:17 Which records aren't in list? Use static list as table or records
Previous Message Jeremy Finzel 2019-05-22 13:01:41 Re: Bulk inserts into two (related) tables