duckdb / sqlite_scanner

DuckDB extension to read and write to SQLite databases
https://duckdb.org/docs/extensions/sqlite
MIT License
208 stars 21 forks source link

Data in SQLite tables with integer primary keys cannot be read unless a positive value exists for the key #37

Closed dreinharth closed 1 year ago

dreinharth commented 1 year ago

What happens?

If a SQLite table is created in SQLite, and contains a single row with an integer primary key value of 0, that row cannot be seen via the DuckDB SQLite scanner. If the row contains only values < 0, DuckDB will hang trying to read the rows.

To Reproduce

  1. Create database and table in SQLite
$ sqlite test.db

sqlite> CREATE TABLE tbl (a INTEGER PRIMARY KEY, b INTEGER);
sqlite> INSERT INTO tbl (a) VALUES (0);
  1. Read from DuckDB
    
    duckdb

D ATTACH 'test.db' (TYPE SQLITE); D SELECT * FROM test.tbl;


- No rows will be returned.
- If any positive values (e.g. `1`) are present, all rows are returned
- If only negative values (e.g. `-1`) are present, the `SELECT` will hang
- If table is created in DuckDB, there is no problem (which database is used for inserts is irrelevant)

### OS:

Linux x64

### SQLite Version:

3.39.4, 3.40.1

### DuckDB Version:

0.7.1, v0.7.2-dev1138

### DuckDB Client:

CLI, Python

### Full Name:

David Reinharth

### Affiliation:

Amazon

### Have you tried this on the latest `master` branch?

- [X] 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?

- [X] I agree