From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-general@lists.postgresql.org
Subject: Re: Use ctid in where clause in update from statement
Date: Mon, 1 Jul 2019 11:35:49 +0200
Message-ID: <d7a5335e-947b-be84-d5c7-11203cb086b8@gmx.net> (raw)
In-Reply-To: <C8D480EC-AFF2-40CC-8BD3-754A1204011A@mikatiming.de>
References: <C8D480EC-AFF2-40CC-8BD3-754A1204011A@mikatiming.de>
> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: spam_eater@gmx.net
Subject: Re: Use ctid in where clause in update from statement
In-Reply-To: <d7a5335e-947b-be84-d5c7-11203cb086b8@gmx.net>
References: <C8D480EC-AFF2-40CC-8BD3-754A1204011A@mikatiming.de> <d7a5335e-947b-be84-d5c7-11203cb086b8@gmx.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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