BUG #18502: Upsert on view returns 42P10 error when condition is an expression - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #18502: Upsert on view returns 42P10 error when condition is an expression
Date
Msg-id 18502-545b53f5b81e54e0@postgresql.org
Whole thread Raw
Responses Re: BUG #18502: Upsert on view returns 42P10 error when condition is an expression
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      18502
Logged by:          Michael Wang
Email address:      michael.wanghai.a@outlook.com
PostgreSQL version: 12.5
Operating system:   Official docker Image run in MacOS 14.3
Description:

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;
```
I tested cast expression and fails as well
```
CREATE UNIQUE INDEX ON my_table ((id::text));
INSERT INTO my_view (id, data)
VALUES ('990cc75c-2e60-4c0d-8bec-9ac976dc03bc'::uuid,
        '{
          "key": "value"
        }'::jsonb)
ON CONFLICT ((id::text))
    DO NOTHING;
```
I also tested `DO UPDATE...`, the same error is returned.
I also tested with the latest official docker image witch is PG 16, same
error returns.


pgsql-bugs by date:

Previous
From: Alexander Lakhin
Date:
Subject: Re: BUG #18483: Segmentation fault in tests modules
Next
From: Alvaro Herrera
Date:
Subject: Re: BUG #18377: Assert false in "partdesc->nparts >= pinfo->nparts", fileName="execPartition.c", lineNumber=1943