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 1hhsjA-0003Y7-2y for pgsql-general@arkaria.postgresql.org; Mon, 01 Jul 2019 09:36:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hhsj8-0003H9-PV for pgsql-general@arkaria.postgresql.org; Mon, 01 Jul 2019 09:35:58 +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 1hhsj8-0003Gy-C9 for pgsql-general@lists.postgresql.org; Mon, 01 Jul 2019 09:35:58 +0000 Received: from mout.kundenserver.de ([217.72.192.75]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hhsj5-0003As-Li for pgsql-general@lists.postgresql.org; Mon, 01 Jul 2019 09:35:57 +0000 Received: from [10.8.0.6] ([185.40.248.10]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.145]) with ESMTPSA (Nemesis) id 1Mhl4Q-1iCWZh3orA-00dlGf for ; Mon, 01 Jul 2019 11:35:49 +0200 Subject: Re: Use ctid in where clause in update from statement To: pgsql-general@lists.postgresql.org References: From: Thomas Kellerer Message-ID: Date: Mon, 1 Jul 2019 11:35:49 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:tH2U/ltGPDkbwUQCB4iOVEluVs75KX54tLjZEhfzChInl3Mznn/ aRJr+kIu6kLrpMJjjbtPsl8NTmY3pL7WfSm2t5pCbUQA/2duPn31cNaPb9/xzk06nLHe7qS j7FCr8a/MrQTRQumuqh48p7mYnFnGWYKcmjoRB4dfQVfifPaD2RhCZZKJ1yjvcpfDeqKvEe S6fryaBk8Mct5QecObIfQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:fqr0PnD01Gw=:rW06ha4H0UhidsEn1BbvsE CQ2BuPLNHmrl9NOHVb3MO3fBlKBQQBH4jvdmHH7wtSocn4jvfakhq+nEfpSKzcG8G62XZgtwW Bz/yMwOmsheGo4/2KAWxoREXp4TA62j7bbgvsuDAwsP6fqybTwYQ4XAGdmyPqDys7xu4cpkLU fB4YmHLK5OPH9FLrI/wuxuT/0e1oa42G2OUW/s+SEkRBXATIaQxSGDJ1orWzvF11LsKnGtmt5 pYoY6zj6vFGf972Y8XzWoo9Wy6FWXvF9O6eB0/i8uzQ1mCS7F5roDAo8EsBriZQihwL8fhATg kP3+ykYM/pZsAbo4apWts1O3s3xh1imWnlOizuNkQSpUvuAKiJSnWL/PNUS79Ab0T0VdGaYAO NzKXgLwfDnfPAZ4OvVaJtTxVuWzZVEy0MutXB4CtIOKXGp9mHjmh22wBiKz5awf88OT0abtJ2 7/oLoBMLBHRqEm8ZFxzZDT3lEYJtA6lZEJjHmXloNkRBsO1ZX+c7gpNfrahBSw8eaJ92AJ7Q8 gicWqoGz5/ecskNWga9PtHbNvi1K3dZ48aenREFFE9f5fBvLkJjj5YmL4ch+kte+CdnVJOfCq GFHa1F1/VK6GWB2tsCmqS65zOI8TtD4IZZDCtD22UCxKBzLRUemKxpk29w+YzxDgVG/x66Jg+ bBJzRdNzbmU4W1hqo82QIhX/+CQKQn+7iArUyXviYuI4ZiNwufWs421jvb1C2r6lLNW++Qmq5 olI/NdaVJYkk56l9pdRWZ8I02qARxJGjr1EGcHMO8QRPagbrsM+EfctowyQ= List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > I come from the Oracle world and am trying to convert some queries to > PostgreSQL syntax. One of these queries is a MERGE statement, which I > converted into an UPDATE SET FROM WHERE construct. In the original > query I use the pseudo column ROWID to match a source row with a > target row. > > In the PostgreSQL version I use the column ctid for this. The above query becomes: > > *UPDATE*test_large d >    *SET* grp = s.grp >   *FROM* (*SELECT* ctid, test_large.* >           *FROM* test_large >          *WHERE* grp = 1) s >  *WHERE* d.ctid = s.ctid; Why don't you join on the primary key column? The ctid comparison is typically quite slow. Thomas