Re: Use ctid in where clause in update from statement

2019-07-01 Thread Tom Lane
Dirk Mika writes: > I know I can join using the pk, but in oracle using the rowid is faster so I > wanted to know, if this is possible in PostgreSQL as well. Existing Postgres releases are not very bright about joins on CTID --- basically merge join is the only plan type you can get for that. v1

Re: Use ctid in where clause in update from statement

2019-07-01 Thread Dirk Mika
Hi Thinking about it, it _has_ to call any BEFORE trigger function as that might change values of the row to be inserted that could possibly change the outcome of the test. Yeah, that was my thought, too. Unfortunately, the affected trigger changes two columns, so I can't change it t

Re: Use ctid in where clause in update from statement

2019-07-01 Thread Thomas Kellerer
> As you can see the trigger function is called for the row I try to > insert, but you can also see that there's no tuple inserted but one > conflicting. Ah, right. Thinking about it, it _has_ to call any BEFORE trigger function as that might change values of the row to be inserted that could

Re: Use ctid in where clause in update from statement

2019-07-01 Thread Achilleas Mantzios
Hello Dirk, pls don't top post, that's the rule here On 1/7/19 2:40 μ.μ., Dirk Mika wrote: I've tried it with the following trigger: CREATE TRIGGER tr_tl_test1 BEFORE INSERT ON public.test_large FOR EACH ROW EXECUTE PROCEDURE tf_tr_tl_test1 () The trigger function does nothing spe

Re: Use ctid in where clause in update from statement

2019-07-01 Thread Dirk Mika
I've tried it with the following trigger: CREATE TRIGGER tr_tl_test1 BEFORE INSERT ON public.test_large FOR EACH ROW EXECUTE PROCEDURE tf_tr_tl_test1 () The trigger function does nothing special: CREATE OR REPLACE FUNCTION public.tf_tr_tl_test1 () RETURNS trigger LANGUAGE 'plpgsql

Re: Use ctid in where clause in update from statement

2019-07-01 Thread Thomas Kellerer
Dirk Mika schrieb am 01.07.2019 um 13:18: > The problem with the INSERT ON CONFLICT is that an insert is tried here > first, which may fire triggers. > > In my case there is a fairly expensive INSERT Trigger ON EACH ROW, which I > would like to avoid. The insert trigger will only be fired if an

Re: Use ctid in where clause in update from statement

2019-07-01 Thread Thomas Kellerer
Dirk Mika schrieb am 01.07.2019 um 12:02: > I know I can join using the pk, but in oracle using the rowid is > faster so I wanted to know, if this is possible in PostgreSQL as > well. Well, in Postgres ctid is not necessarily faster.

Re: Use ctid in where clause in update from statement

2019-07-01 Thread Dirk Mika
I know I can join using the pk, but in oracle using the rowid is faster so I wanted to know, if this is possible in PostgreSQL as well. Dirk -- Dirk Mika Software Developer mika:timing GmbH Strundepark - Kürtener Str. 11b 51465 Bergisch Gladbach Germany fon +49 2202 2401-1197 dirk.m...@mikati

Re: Use ctid in where clause in update from statement

2019-07-01 Thread Thomas Kellerer
> 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. > >