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

UPDATE .. RETURNING doesn't work if there's a PRIMARY KEY or UNIQUE constraint on the table #7215

Open
2 tasks done
lukaseder opened this issue Apr 24, 2023 · 3 comments
Open
2 tasks done

Comments

@lukaseder
Copy link

What happens?

I can't use UPDATE .. RETURNING on a table with PRIMARY KEY

To Reproduce

create table t (i int primary key, j int);
insert into t values (1, 1);
update t set j = 2 where i = 1 returning *;

This produces:

Constraint Error: Duplicate key "i: 1" violates primary key constraint

This works, as a workaround:

create table t (i int primary key, j int);
insert into t values (1, 1);
update t set j = 2 where i = 1;
select * from t where i = 1;

Removing the PRIMARY KEY also solves the problem

create table t (i int, j int);
insert into t values (1, 1);
update t set j = 2 where i = 1 returning *;

OS:

Microsoft Windows [Version 10.0.22621.1555]

DuckDB Version:

v0.7.2-dev2430

DuckDB Client:

JDBC

Full Name:

Lukas Eder

Affiliation:

Data Geekery / jOOQ

Have you tried this on the latest master branch?

  • I agree

Have you tried the steps to reproduce? Do they include all relevant data and configuration? Does the issue you report still appear there?

  • I agree
@github-actions
Copy link

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the stale label Jul 28, 2023
@Mause Mause removed the stale label Jul 28, 2023
@taniabogatsch taniabogatsch removed their assignment Aug 24, 2023
@edyu
Copy link

edyu commented Oct 25, 2023

Even removing foreign key constraints, you'll get a constrain error:

Constraint Error: Duplicate key "id: 5d7739ff-012f-4368-ad52-d6a6a58f2699" 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).

The current documentation doesn't show RETURNING as part of UPDATE statement so I'd be happier even if you throw out wrong/illegal SQL error than this vague constraint error.
Note that once I remove returning clause, it would work.
see #8988 for more info.

Copy link

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants