SQLite 在插入时声明重复行,而可以找到 none
SQLite claims duplicate rows on insert whereas none can be found
我在使用以下代码创建的 SQLite 数据库中有一个 table。注意复合主键:
db.create_table(:person_hash) do
Integer :person_id
Bignum :hash // MD5 hash in hex stored as numeric: hash.to_i(16)
primary_key [:person_id, :hash]
end
这个 table 已经有一些行:
puts db[:person_hash].where(:person_id => 285577).all
# {:person_id=>285577, :hash=>306607097659338192312932577746542919680}
现在,当我尝试插入这个时:
db[:person_hash].insert({:person_id=>285577, :hash=>306607097659338206333361532286405644297})
我明白了:
SQLite3::ConstraintException: columns person_id, hash are not unique (Sequel::DatabaseError)
如果 table 中不存在该行,怎么会重复?
我尝试为同一个人 ID 插入另一个散列,但没有问题。
这似乎是 SQLite 中的错误:
$ sqlite3
SQLite version 3.8.9 OpenBSD
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> CREATE TABLE person_hash (person_id integer, hash bigint, primary key (person_id, hash));
sqlite> INSERT INTO person_hash VALUES (285577, 306607097659338192312932577746542919680);
sqlite> INSERT INTO person_hash VALUES (285577, 306607097659338206333361532286405644297);
Error: UNIQUE constraint failed: person_hash.person_id, person_hash.hash
我在使用以下代码创建的 SQLite 数据库中有一个 table。注意复合主键:
db.create_table(:person_hash) do
Integer :person_id
Bignum :hash // MD5 hash in hex stored as numeric: hash.to_i(16)
primary_key [:person_id, :hash]
end
这个 table 已经有一些行:
puts db[:person_hash].where(:person_id => 285577).all
# {:person_id=>285577, :hash=>306607097659338192312932577746542919680}
现在,当我尝试插入这个时:
db[:person_hash].insert({:person_id=>285577, :hash=>306607097659338206333361532286405644297})
我明白了:
SQLite3::ConstraintException: columns person_id, hash are not unique (Sequel::DatabaseError)
如果 table 中不存在该行,怎么会重复?
我尝试为同一个人 ID 插入另一个散列,但没有问题。
这似乎是 SQLite 中的错误:
$ sqlite3
SQLite version 3.8.9 OpenBSD
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> CREATE TABLE person_hash (person_id integer, hash bigint, primary key (person_id, hash));
sqlite> INSERT INTO person_hash VALUES (285577, 306607097659338192312932577746542919680);
sqlite> INSERT INTO person_hash VALUES (285577, 306607097659338206333361532286405644297);
Error: UNIQUE constraint failed: person_hash.person_id, person_hash.hash