pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: 德哥 <digoal@126.com>
To: jian he <jian.universality@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re:Re: BUG #17845: insert into on conflict bug .
Date: Fri, 17 Mar 2023 10:34:53 +0800 (CST)
Message-ID: <5a1545f3.1e8a.186ed6b8959.Coremail.digoal@126.com> (raw)
In-Reply-To: <CACJufxGDczsEW0-3D8ba1NeACOD7rP9eVXBBkjHiupFq4u0StQ@mail.gmail.com>
References: <17845-fee889ae7e226a76@postgresql.org>
	<CACJufxGDczsEW0-3D8ba1NeACOD7rP9eVXBBkjHiupFq4u0StQ@mail.gmail.com>

In this case, `where a.ts < exclude. ts` and `order by ts desc` are used. The ts of the tuple inserted first is the largest. So why throw an error? Throwing an error here is obviously not logically correct.



在 2023-03-16 22:28:27,"jian he" <jian.universality@gmail.com> 写道:





On Thu, Mar 16, 2023 at 5:42 PM PG Bug reporting form <noreply@postgresql.org> wrote:

The following bug has been logged on the website:

Bug reference:      17845
Logged by:          Zhou Digoal
Email address:      digoal@126.com
PostgreSQL version: 15.2
Operating system:   macos
Description:       

insert into on conflict bug .
In the following insert statement, the row has not been updated multiple
times, why is it still showing an error?

```
create table a (id int primary key, info text, ts date);


insert into a
select * from (values (1,'a',date '2022-01-01'),(1,'b',date
'2022-01-02'),(1,'c',date '2022-01-03')) as t (id,info,ts) order by ts
desc
on conflict (id)
do update set info=excluded.info, ts=excluded.ts where a.ts < excluded.ts ;



                                QUERY PLAN                               
--------------------------------------------------------------------------
 Insert on a  (cost=0.06..0.10 rows=0 width=0)
   Conflict Resolution: UPDATE
   Conflict Arbiter Indexes: a_pkey
   Conflict Filter: (a.ts < excluded.ts)
   ->  Sort  (cost=0.06..0.07 rows=3 width=40)
         Sort Key: "*VALUES*".column3 DESC
         ->  Values Scan on "*VALUES*"  (cost=0.00..0.04 rows=3 width=40)
(7 rows)


ERROR:  21000: ON CONFLICT DO UPDATE command cannot affect row a second
time
HINT:  Ensure that no rows proposed for insertion within the same command
have duplicate constrained values.
LOCATION:  ExecOnConflictUpdate, nodeModifyTable.c:2054
```




it's expected behavior.

See the test expected result in src/test/regress/expected/insert_conflict.out, begin with line 694.

view thread (9+ messages)  latest in thread

Message-ID: <5a1545f3.1e8a.186ed6b8959.Coremail.digoal@126.com>
Permalink:  ../5a1545f3.1e8a.186ed6b8959.Coremail.digoal@126.com/
Also on:    postgresql.org/message-id/5a1545f3.1e8a.186ed6b8959.Coremail.digoal@126.com

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: digoal@126.com, jian.universality@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re:Re: BUG #17845: insert into on conflict bug .
  In-Reply-To: <5a1545f3.1e8a.186ed6b8959.Coremail.digoal@126.com>

* 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