duckdb-rs icon indicating copy to clipboard operation
duckdb-rs copied to clipboard

[BUG] 'gen_random_uuid()' Constraint Error: Duplicate key

Open wyhaya opened this issue 1 year ago • 1 comments

[dependencies]
duckdb = { version = "0.10.2", features = ["bundled"] }
use duckdb::Connection;

fn main() {
    let conn = Connection::open_in_memory().unwrap();
    conn.execute("CREATE TABLE test (id uuid primary key default gen_random_uuid())", []).unwrap();
    for _ in 0..999999 {
        conn.execute("insert into test default values", []).unwrap();
    }
}
cargo run --release
thread 'main' panicked at src/main.rs:12:61:
called `Result::unwrap()` on an `Err` value: DuckDBFailure(Error { code: Unknown, extended_code: 1 }, 
Some("Constraint Error: Duplicate key \"id: 620e391f-bf1c-412e-9fc3-917224f99a1c\" violates primary key constraint.
If this is an unexpected constraint violation please double check with the known index limitations section in our documentation (https://duckdb.org/docs/sql/indexes)."))
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

In fact, I'm not quite sure whether this bug should belong to duckdb-rs, but I'm unfamiliar with C++, and I can't check it further, so I posted it here.

macOS 14.5 select version() -> v0.10.2

wyhaya avatar Jun 07 '24 13:06 wyhaya

Sounds like a problem on https://github.com/duckdb/duckdb

Swoorup avatar Jun 08 '24 15:06 Swoorup

Sounds like a problem on https://github.com/duckdb/duckdb

Yes, I could reproduce it with a simple SQL .test. I'll open an issue for us to pick this up. 👍 Linking this related issue: https://github.com/marcboeker/go-duckdb/issues/339.

statement ok
CREATE TABLE test (id UUID PRIMARY KEY DEFAULT gen_random_uuid());

concurrentloop i 0 20

loop j 0 10000

statement ok
INSERT INTO test DEFAULT VALUES;

endloop

endloop
(venv) tania@motorbook duckdb % build/release/test/unittest test/temp.test
Filters: test/temp.test
[0/1] (0%): test/temp.test                                                      ================================================================================
Query unexpectedly failed! (test/temp.test:11)!
================================================================================
INSERT INTO test DEFAULT VALUES;
================================================================================
Constraint Error: Duplicate key "id: 7c047142-09fd-4666-8381-5794fc888e23" violates primary key constraint.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
unittest is a Catch v2.13.7 host application.
Run with -? for options

-------------------------------------------------------------------------------
test/temp.test
-------------------------------------------------------------------------------
/Users/tania/DuckDB/duckdb/test/sqlite/test_sqllogictest.cpp:210
...............................................................................

test/temp.test:11: FAILED:
explicitly with message:
  0

[1/1] (100%): test/temp.test                                                    
===============================================================================
test cases:     1 |     0 passed | 1 failed
assertions: 58757 | 58756 passed | 1 failed

taniabogatsch avatar Dec 27 '24 11:12 taniabogatsch