sqlite_scanner icon indicating copy to clipboard operation
sqlite_scanner copied to clipboard

Data Type Mismatch Exceptions are raised as generic Exception and not TypeMismatchException

Open d33bs opened this issue 2 years ago • 1 comments

What happens?

When querying data values which mismatch the column type in DuckDB using Python a generic duckdb.Exception is encountered instead of duckdb.TypeMismatchException. I'm opening this issue as it seemed there is an opportunity to better align existing exceptions so they may be handled appropriately within Python.

To Reproduce

import sqlite3

import duckdb

# create a temporary sqlite file location
filepath = ".example.sqlite"

# statements for creating database with simple structure
create_stmts = """
    DROP TABLE IF EXISTS tbl_a;
    CREATE TABLE tbl_a (
        col_integer INTEGER NOT NULL
        ,col_text TEXT
        ,col_blob BLOB
        ,col_real REAL
    );
    """

# some example values to insert into the database
insert_vals = ["nan", "sample", b"sample_blob", 0.5]

# create the database and insert some data into it
with sqlite3.connect(filepath) as connection:
    connection.executescript(create_stmts)

    connection.execute(
        (
            "INSERT INTO tbl_a (col_integer, col_text, col_blob, col_real)"
            "VALUES (?, ?, ?, ?);"
        ),
        insert_vals,
    )

try:
    duckdb.connect().execute(
        f"""
    /* install and load sqlite plugin for duckdb */
    INSTALL sqlite_scanner;
    LOAD sqlite_scanner;

    /* perform query on tbl_a table */
    SELECT * FROM sqlite_scan('{filepath}', 'tbl_a');
    """
    ).arrow()
    
except duckdb.TypeMismatchException as type_mismatch_e:
    print("Found a type mismatch exception: ", type_mismatch_e)
    
except Exception as e:
    print("Found a different error of type: ", type(e), e, sep="\n")

OS:

MacOS

SQLite Version:

3.37.0

DuckDB Version:

0.7.1, 0.8.0

DuckDB Client:

Python

Full Name:

Dave Bunten

Affiliation:

University of Colorado

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

d33bs avatar May 24 '23 18:05 d33bs

This is probably caused by https://github.com/duckdb/duckdb/issues/6521

Mause avatar Jun 06 '23 04:06 Mause