Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hTSGD-0004U2-Dq for pgsql-general@arkaria.postgresql.org; Wed, 22 May 2019 14:30:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hTSG9-0003sz-D9 for pgsql-general@arkaria.postgresql.org; Wed, 22 May 2019 14:30:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hTSG8-0003sg-V8 for pgsql-general@lists.postgresql.org; Wed, 22 May 2019 14:30:25 +0000 Received: from smtp5-g21.free.fr ([212.27.42.5]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hTSG1-0007aC-SR for pgsql-general@lists.postgresql.org; Wed, 22 May 2019 14:30:23 +0000 Received: from mail.tol.fr (unknown [IPv6:2a01:e34:eeaf:c5f0:21e:62ff:fe00:36]) by smtp5-g21.free.fr (Postfix) with ESMTP id C7A8460005; Wed, 22 May 2019 16:30:13 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.tol.fr (Postfix) with ESMTP id 0B76C246CB; Wed, 22 May 2019 16:30:13 +0200 (CEST) Received: from mail.tol.fr ([IPv6:::1]) by localhost (mail.couderc.eu [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id rA5iAv-EiAIY; Wed, 22 May 2019 16:30:12 +0200 (CEST) Received: from [192.168.163.11] (unknown [192.168.163.11]) by mail.tol.fr (Postfix) with ESMTPSA id 8F0F5246C8; Wed, 22 May 2019 16:30:12 +0200 (CEST) Subject: Re: how to write correctly this update ? To: Rob Sargent Cc: "pgsql-generallists.postgresql.org" References: <388af3c8-bfcf-8e38-4634-7ebda366f410@couderc.eu> <7D3837A3-CFEC-4D65-AC70-12193C1124D2@gmail.com> From: Pierre Couderc Message-ID: Date: Wed, 22 May 2019 16:30:12 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <7D3837A3-CFEC-4D65-AC70-12193C1124D2@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: fr-classic List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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 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 >> >> >> >> >> >>