pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
how to write correctly this update ?
3+ messages / 2 participants
[nested] [flat]

* how to write correctly this update ?
@ 2019-05-22 12:43 Pierre Couderc <pierre@couderc.eu>
  2019-05-22 13:19 ` Re: how to write correctly this update ? Rob Sargent <robjsargent@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Pierre Couderc @ 2019-05-22 12:43 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

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









^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: how to write correctly this update ?
  2019-05-22 12:43 how to write correctly this update ? Pierre Couderc <pierre@couderc.eu>
@ 2019-05-22 13:19 ` Rob Sargent <robjsargent@gmail.com>
  2019-05-22 14:30   ` Re: how to write correctly this update ? Pierre Couderc <pierre@couderc.eu>
  0 siblings, 1 reply; 3+ messages in thread

From: Rob Sargent @ 2019-05-22 13:19 UTC (permalink / raw)
  To: Pierre Couderc <pierre@couderc.eu>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

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@couderc.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
> 
> 
> 
> 
> 
> 






^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: how to write correctly this update ?
  2019-05-22 12:43 how to write correctly this update ? Pierre Couderc <pierre@couderc.eu>
  2019-05-22 13:19 ` Re: how to write correctly this update ? Rob Sargent <robjsargent@gmail.com>
@ 2019-05-22 14:30   ` Pierre Couderc <pierre@couderc.eu>
  0 siblings, 0 replies; 3+ messages in thread

From: Pierre Couderc @ 2019-05-22 14:30 UTC (permalink / raw)
  To: Rob Sargent <robjsargent@gmail.com>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>


On 5/22/19 3:19 PM, Rob Sargent wrote:
> 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;
Wow, fine ! you got  it!
>
> (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.)
Now I check manually... ;)
>
>> On May 22, 2019, at 6:43 AM, Pierre Couderc <pierre@couderc.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
>>
>>
>>
>>
>>
>>





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2019-05-22 14:30 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-05-22 12:43 how to write correctly this update ? Pierre Couderc <pierre@couderc.eu>
2019-05-22 13:19 ` Rob Sargent <robjsargent@gmail.com>
2019-05-22 14:30   ` Pierre Couderc <pierre@couderc.eu>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox