Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Duplicate key' error when update column with list data type and table has a primary key #11915

Closed
2 tasks done
lpfy opened this issue May 3, 2024 · 2 comments
Closed
2 tasks done
Labels
expected behavior The behavior described in the issue is expected Needs Documentation Use for issues or PRs that require changes in the documentation needs triage

Comments

@lpfy
Copy link

lpfy commented May 3, 2024

What happens?

This behaviour happens for both Python and WASM (https://shell.duckdb.org/) environments. There is no way to update the column with the list data type and the table has a primary key. The UPDATE query always return 'Duplicate key' error.

To Reproduce

create or replace table test (
	aid INT, 
        comments TEXT,
	alist STRUCT(username VARCHAR, lid INT)[],
	PRIMARY KEY (aid)
);

insert into test select 1, 'abc', [{username:'t1',lid:1},{username:'t2',lid:2}];
insert into test select 2, 'def', [{username:'t3',lid:3},{username:'t4',lid:4}];
UPDATE test SET comments = 'test test' WHERE aid = 1;
UPDATE test SET alist = [{username:'t5',lid:5},{username:'t6',lid:6}] WHERE aid = 1;

the last update query will return the following error:

Constraint Error: Duplicate key "aid: 1" violates primary key constraint. If this is an unexpected constraint violation please double check with the known index limitations section in our documentation (docs - sql - indexes).

I am not updating the primary key column, and the comments column can be updated, just the column with list data type is causing the problem.

OS:

Browser / Windows / Linux

DuckDB Version:

0.10.2

DuckDB Client:

WASM or Python

Full Name:

Sasha Zhang

Affiliation:

Unisa

What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have tested with a stable release

Did you include all relevant data sets for reproducing the issue?

Yes

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant configuration (e.g., CPU architecture, Python version, Linux distribution) to reproduce the issue?

  • Yes, I have
@szarnyasg
Copy link
Collaborator

Hi @lpfy, thanks for raising this issue. As described in this (quite well-hidden) comment, updates on lists are implemented as as sequence of delete and insert operations, which can trigger duplicates. I'll update this in the documentation.

@lpfy
Copy link
Author

lpfy commented May 17, 2024

@szarnyasg Thanks, I have noticed the new documentation is live. https://duckdb.org/docs/sql/data_types/list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
expected behavior The behavior described in the issue is expected Needs Documentation Use for issues or PRs that require changes in the documentation needs triage
Projects
None yet
Development

No branches or pull requests

2 participants