Skip to content

SQlite and dataframes #275

Description

@jondan99

Hello

I am reading a sqlite table into a dataframe, where one column is
r real
and all values are missing. I use
df=DBInterface.execute(db, sql) |> DataFrame;
and get df.r to be of type missing (think it should be Union{Missing,Float64} )
SQLite.jl returns the correct type, but it does not make it when converted to a dataframe.

not sure if this is a bug, but thought I would let you all know

best, jack

Activity

  1. nalimilan commented on Nov 28, 2021

    @nalimilan

    This is probably due to:

    return nothing # fallback to the actual column types of the result

    @quinnj What's the reason for using the actual content types instead of the ones declared in the SQL table?

  2. quinnj commented on Dec 2, 2021

    @quinnj
    Member

    This is the default definition because in sqlite, declared column types are just "suggestions" instead of any kind of real constraint. Indeed, you can declare a column type to be DOUBLE, but then insert as many strings as you want and it won't complain. Hence we ran into too many issues where this "flexibility" caused issues when trying to query data from a table.

    I think we should bring back the stricttypes::Bool=false keyword argument though, so you could do DBInterface.execute(db, sql; stricttypes=true) and it would produce a Tables.Schema that returns the declared column types.

  3. quinnj commented on Oct 4, 2026

    @quinnj
    Member

    This is supported through the strict result option added in #304, included in v1.6.0. I verified registered SQLite.jl 1.9.0 on Julia 1.9.4 and 1.13.1: an all-NULL REAL column becomes Union{Missing,Float64} when using the prepared-statement form:

    stmt = DBInterface.prepare(db, sql)
    df = try
        DataFrame(DBInterface.execute(stmt, (); strict=true))
    finally
        DBInterface.close!(stmt)
    end

    The explicit () is the parameter collection. It lets strict=true reach SQLite's result option; the connection/SQL keyword convenience form treats keywords as bound query parameters instead. Default result reading still infers types from values to handle SQLite's flexible column typing.

    Both runtimes pass seven checks for row counts, all-missing values, strict column types, and an empty result's declared type. Closing this as implemented without changing the default behavior.

    AI disclosure: This work was prepared with assistance from OpenAI Codex.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions