目标:使用Julia中的LibPQ创建记录并将其插入到postgres中>>
代码:
using LibPQ, DataStreams, DataFrames; host="localhost"; port="5432"; db="practice"; user="pdm"; pwd="pdm123"; ddq = "DROP TABLE IF EXISTS practice.language; CREATE TABLE IF NOT EXISTS practice.language (lang TEXT, web TEXT)"; conn = LibPQ.Connection("host=$host dbname=$db user=$user password=$pwd"); result = execute(conn, ddq); langs = DataFrame(langv=["Julia","Go","Rust"], webv=["julialang.org", "golang.org", "www.rust-lang.org"]); dmq = "INSERT INTO practice.language (lang, web) VALUES(\$1, \$2))"; Data.stream!(langs, LibPQ.Statement, conn, dmq); close(conn);
观察:
创建表练习。语言但未插入记录。
practice=> select * from practice.language; lang | web ------+----- (0 rows)
错误日志:
ERROR: LoadError: MethodError: no method matching schema(::DataFrame) Closest candidates are: schema(::S, ::DataStreams.Data.Query{c,columns,e,limit,offset}) where {c, S, columns, e, limit, offset} at /opt/julia/julia-1.1.0/share/julia/stdlib/v1.1/packages/DataStreams/mEqAy/src/query.jl:217 schema(::S, ::DataStreams.Data.Query{c,columns,e,limit,offset}, ::Any) where {c, S, columns, e, limit, offset} at /opt/julia/julia-1.1.0/share/julia/stdlib/v1.1/packages/DataStreams/mEqAy/src/query.jl:217 schema(::Array{NamedTuple{names,T},1}) where {names, T} at /opt/julia/julia-1.1.0/share/julia/stdlib/v1.1/packages/DataStreams/mEqAy/src/namedtuples.jl:26 ... Stacktrace: [1] #stream!#111(::Bool, ::Dict{Int64,Function}, ::Function, ::Array{Any,1}, ::Array{Any,1}, ::Nothing, ::Nothing, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(DataStreams.Data.stream!), ::DataFrame, ::Type{LibPQ.Statement}, ::LibPQ.Connection, ::Vararg{Any,N} where N) at /opt/julia/julia-1.1.0/share/julia/stdlib/v1.1/packages/DataStreams/mEqAy/src/query.jl:534 [2] stream!(::DataFrame, ::Type{LibPQ.Statement}, ::LibPQ.Connection, ::String) at /opt/julia/julia-1.1.0/share/julia/stdlib/v1.1/packages/DataStreams/mEqAy/src/query.jl:516 [3] top-level scope at none:0 [4] include at ./boot.jl:326 [inlined] [5] include_relative(::Module, ::String) at ./loading.jl:1038 [6] include(::Module, ::String) at ./sysimg.jl:29 [7] include(::String) at ./client.jl:403 [8] top-level scope at none:0 in expression starting at /root/pgtest.jl:12
请指导解决上述问题,以及有关使用LibPQ在Julia中进行参数化获取记录的示例。
目标:使用julia中的LibPQ创建记录并将其插入到postgres中。使用LibPQ,DataStreams,DataFrames; host =“ localhost”; port =“ 5432”; db =“ practice”; user =“ pdm”; pwd =“ pdm123”; ddq =“ ...
如何使用LibPQ.load!