pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: 王 海 <michael.wanghai.a@outlook.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Peter Geoghegan <pg@bowt.ie>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject:  回复: BUG #18502: Upsert on view returns 42P10 error when condition is an expression
Date: Wed, 12 Jun 2024 02:11:01 +0000
Message-ID: <TYCP286MB28619F2053FA2AFB7BDC6ED8EAC02@TYCP286MB2861.JPNP286.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <1153168.1718139271@sss.pgh.pa.us>
References: <18502-545b53f5b81e54e0@postgresql.org>
	<1153168.1718139271@sss.pgh.pa.us>

Thanks for the analysis. May I ask how long will it cost normally for such bug fix being released since I'm new to the community? And will it be back port to PG 12?

Hai Wang
________________________________
发件人: Tom Lane <tgl@sss.pgh.pa.us>
发送时间: 2024年6月12日 4:54
收件人: michael.wanghai.a@outlook.com <michael.wanghai.a@outlook.com>
抄送: Peter Geoghegan <pg@bowt.ie>; pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
主题: Re: BUG #18502: Upsert on view returns 42P10 error when condition is an expression

PG Bug reporting form <noreply@postgresql.org> writes:
> I have a table, index and view like following:
> ```
> CREATE TABLE my_table
> (
>     id   uuid primary key,
>     data jsonb not null
> );
> CREATE UNIQUE INDEX ON my_table ((data ->> 'key'));
> CREATE VIEW my_view AS SELECT * FROM my_table;
> ```
> The upsert on view returns 42P10 error when I execute the following SQL
> ```
> INSERT INTO my_view (id, data)
> VALUES ('990cc75c-2e60-4c0d-8bec-9ac976dc03bc'::uuid,
>         '{
>           "key": "value"
>         }'::jsonb)
> ON CONFLICT ((data ->> 'key'))
>     DO NOTHING;
> ```

For the archives' sake: the error being complained of is

ERROR:  there is no unique or exclusion constraint matching the ON CONFLICT specification

Thanks for the report.  The fault lies with infer_arbiter_indexes(),
which assumes that it can match the output of
RelationGetIndexExpressions or RelationGetIndexPredicate
directly to the query without adjusting varnos.  That works
most of the time, because the INSERT target typically has
varno 1, matching the way these trees are stored in the catalogs.
But not so much when we've flattened an updatable view;
so the match fails even when it should succeed.

The attached seems to be enough to fix it.

                        regards, tom lane



Message-ID: <TYCP286MB28619F2053FA2AFB7BDC6ED8EAC02@TYCP286MB2861.JPNP286.PROD.OUTLOOK.COM>
Permalink:  ../TYCP286MB28619F2053FA2AFB7BDC6ED8EAC02@TYCP286MB2861.JPNP286.PROD.OUTLOOK.COM/
Also on:    postgresql.org/message-id/TYCP286MB28619F2053FA2AFB7BDC6ED8EAC02@TYCP286MB2861.JPNP286.PROD.OUTLOOK.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: michael.wanghai.a@outlook.com, tgl@sss.pgh.pa.us, pg@bowt.ie, pgsql-bugs@lists.postgresql.org
  Subject: Re:  回复: BUG #18502: Upsert on view returns 42P10 error when condition is an expression
  In-Reply-To: <TYCP286MB28619F2053FA2AFB7BDC6ED8EAC02@TYCP286MB2861.JPNP286.PROD.OUTLOOK.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