Skip to content

Repeat calls to load!(...) fail #274

@NicholasWMRitchie

Description

@NicholasWMRitchie

If I create a database, load a data frame in using the load!(..) function it creates a table in the database. However, if I call load!(...) a second time with additional similarly structured data, it fails with the error shown below.

using SQLite
using DataFrames

db=SQLite.DB(joinpath(@__DIR__,"crap.db")
df=DataFrame(A=collect(1:10), B=collect(map(i->i*i,1:10)), C=collect(map(i->sin(i),1:10)))
df |> SQLite.load!(db, "Table")
df2=DataFrame(A=collect(11:20), B=collect(map(i->i*i,11:20)), C=collect(map(i->sin(i),11:20)))
df2 |> SQLite.load!(db, "Table")

ERROR: MethodError: promote_type(::Type{Union{}}, ::Type{String}) is ambiguous. Candidates:
promote_type(::Type{Union{}}, ::Type{T}) where T in Base at promotion.jl:224
promote_type(::Type{T}, ::Type{String}) where T<:WeakRefStrings.InlineString in WeakRefStrings at C:\Users\nritchie\.julia\packages\WeakRefStrings\a3jYm\src\inlinestrings.jl:44
Possible fix, define
promote_type(::Type{Union{}}, ::Type{String})
Stacktrace:
[1] add_or_widen!(val::String, col::Int64, nm::Symbol, dest::Tables.EmptyVector, row::Int64, updated::Base.RefValue{Any}, L::Base.SizeUnknown)
  @ Tables C:\Users\nritchie\.julia\packages\Tables\OWzlh\src\fallbacks.jl:150
[2] eachcolumns
  @ C:\Users\nritchie\.julia\packages\Tables\OWzlh\src\utils.jl:127 [inlined]
[3] _buildcolumns(rowitr::SQLite.Query, row::SQLite.Row, st::Int64, sch::Tables.Schema{(:cid, :name, :type, :notnull, :dflt_value, :pk), nothing}, columns::NTuple{6, Tables.EmptyVector}, updated::Base.RefValue{Any})
  @ Tables C:\Users\nritchie\.julia\packages\Tables\OWzlh\src\fallbacks.jl:187
[4] buildcolumns
  @ C:\Users\nritchie\.julia\packages\Tables\OWzlh\src\fallbacks.jl:217 [inlined]
[5] columns
  @ C:\Users\nritchie\.julia\packages\Tables\OWzlh\src\fallbacks.jl:253 [inlined]
[6] columntable(itr::SQLite.Query)
  @ Tables C:\Users\nritchie\.julia\packages\Tables\OWzlh\src\namedtuples.jl:171
[7] (::SQLite.var"#23#24")(qry::SQLite.Query)
  @ SQLite C:\Users\nritchie\.julia\packages\SQLite\5DdLp\src\tables.jl:169
[8] execute(f::SQLite.var"#23#24", stmt::SQLite.Stmt, params::NamedTuple{(), Tuple{}})
  @ DBInterface C:\Users\nritchie\.julia\packages\DBInterface\1Gmxx\src\DBInterface.jl:135
[9] execute(f::Function, conn::SQLite.DB, sql::String, params::NamedTuple{(), Tuple{}})
  @ DBInterface C:\Users\nritchie\.julia\packages\DBInterface\1Gmxx\src\DBInterface.jl:144
[10] #execute#3
  @ C:\Users\nritchie\.julia\packages\DBInterface\1Gmxx\src\DBInterface.jl:153 [inlined]
[11] execute
  @ C:\Users\nritchie\.julia\packages\DBInterface\1Gmxx\src\DBInterface.jl:153 [inlined]
[12] tableinfo
  @ C:\Users\nritchie\.julia\packages\SQLite\5DdLp\src\tables.jl:165 [inlined]
[13] load!(itr::DataFrame, db::SQLite.DB, name::String; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
  @ SQLite C:\Users\nritchie\.julia\packages\SQLite\5DdLp\src\tables.jl:195
[14] load!
  @ C:\Users\nritchie\.julia\packages\SQLite\5DdLp\src\tables.jl:195 [inlined]
[15] #26
  @ C:\Users\nritchie\.julia\packages\SQLite\5DdLp\src\tables.jl:191 [inlined]
[16] |>(x::DataFrame, f::SQLite.var"#26#27"{Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SQLite.DB, String})
  @ Base .\operators.jl:858
[17] top-level scope
  @ REPL[8]:1``

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