如何在julia中绑定LibPQ中的参数及其值?

如何在julia中绑定LibPQ中的参数及其值?,julia,Julia,我想随机生成记录,并在julia中使用LibPQ插入postgresql 用户表ddl: CREATE TABLE IF NOT EXISTS practice.users( id bigserial PRIMARY KEY, created_at timestamp, name text, email text, address text, city text, state text, zip

我想随机生成记录,并在julia中使用LibPQ插入postgresql

用户表ddl:

CREATE TABLE IF NOT EXISTS practice.users(
  id         bigserial PRIMARY KEY,
  created_at timestamp,
  name       text,
  email      text,
  address    text,
  city       text,
  state      text,
  zip        text,
  birth_date text,
  latitude   float,
  longitude  float,
  password   text,
  source     text
);
文件gen_users.jl中的代码:

using LibPQ, DataStreams, DataFrames, Dates, Random;

global fnames = ["Oliver", "Jake", "Noah"];

global lnames=["Smith", "Murphy", "Smith"];

global esps = ["gmail", "yahoo", "outlook"];

global tlds = ["com"];

global cities = ["Montgomery", "Juneau", "Phoenix"];

global states = ["Alabama", "Alaska", "Arizona"];

host="localhost";
port="5432";
db="practice";
user="ydba";
pwd="ydba123";


function insert_user()
conn = LibPQ.Connection("host=$host dbname=$db user=$user password=$pwd");
    for i in 1:1
        ###user_id::Int64
        created_at_val = rand(DateTime("2019-01-01"):Second(1):DateTime("2020-01-20"));
        fname = fnames[rand(1 : size(fnames)[1])];
        lname = lnames[rand(1 : size(lnames)[1])];
        name_val = fname * " " * lname;
        email_val = fname * "." * lname * "@" * esps[rand(1 : size(esps)[1])] * "." * tlds[rand(1 : size(tlds)[1])];
        address_val = "D No." * randstring('1':'9', 3) * ", " * rand(["Left", "Right", "A", "B", "C", "D"]) * " Wing, " * rand(["I", "II", "III"]) * " Floor, " * rand(["Daffodil", "Lotus", "Jasmine", "Rose", "Lily"]) * "Building, " * rand(["I", "II", "III"]) * " Avenue, " * randstring('A':'Z') * " Block, " * randstring('A':'Z') * " Sector, ";
        city_val = cities[rand(1 : size(cities)[1])];
        state_val = states[rand(1 : size(states)[1])];
        zip_val = randstring('1':'9', 9);
        birth_date_val = rand(DateTime("1919-01-01"):Day(1):DateTime("2000-05-30"));
        latitude_val = rand(-90.0:90.0);
        longtitude_val = rand(-180.0:180.0);
        password_val = randstring(['A':'Z'; 'a':'z'; '0':'9'], 8);
        source_val = randstring(['A':'Z'; 'a':'z'; '0':'9'], 8);    
        insert_query = "INSERT INTO practice.users (id, created_at, name, email, address, city, state, zip, birth_date, latitude, longitude, password, source) VALUES(nextval('practice.users_id_seq'), \$1, \$2, \$3, \$4, \$5, \$6, \$7, \$8, \$9, \$10, \$11, \$12)";
        LibPQ.load!((created_at = created_at_val, name = name_val, email = email_val, address = address_val, city = city_val, state = state_val, zip = zip_val, birth_date = birth_date_val, latitude = latitude_val, longtitude = longtitude_val, password = password_val, source = source_val), conn, insert_query);
        execute(conn, "COMMIT");
    end
close(conn);
end

insert_user();
错误日志:

[error | LibPQ]: ERROR:  bind message supplies 1 parameters, but prepared statement "__libpq_stmt_0__" requires 12

ERROR: LoadError: ERROR:  bind message supplies 1 parameters, but prepared statement "__libpq_stmt_0__" requires 12

Stacktrace:
 [1] error(::Memento.Logger, ::String) at /opt/julia/julia-1.1.0/share/julia/stdlib/v1.1/packages/Memento/UgJr2/src/loggers.jl:429
 [2] #handle_result#45(::Bool, ::Function, ::LibPQ.Result) at /opt/julia/julia-1.1.0/share/julia/stdlib/v1.1/packages/LibPQ/dhdTB/src/results.jl:175
 [3] #handle_result at ./none:0 [inlined]
 [4] #execute#62(::Bool, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::LibPQ.Statement, ::Array{Union{Missing, String},1}) at /opt/julia/julia-1.1.0/share/julia/stdlib/v1.1/packages/LibPQ/dhdTB/src/statements.jl:130
 [5] (::getfield(LibPQ, Symbol("#kw##execute")))(::NamedTuple{(:throw_error,),Tuple{Bool}}, ::typeof(execute), ::LibPQ.Statement, ::Array{Union{Missing, String},1}) at ./none:0
 [6] load!(::NamedTuple{(:created_at, :name, :email, :address, :city, :state, :zip, :birth_date, :latitude, :longtitude, :password, :source),Tuple{DateTime,String,String,String,String,String,String,DateTime,Float64,Float64,String,String}}, ::LibPQ.Connection, ::String) at /opt/julia/julia-1.1.0/share/julia/stdlib/v1.1/packages/LibPQ/dhdTB/src/tables.jl:166
 [7] insert_user() at /root/gen_users.jl:169
 [8] top-level scope at none:0
 [9] include at ./boot.jl:326 [inlined]
 [10] include_relative(::Module, ::String) at ./loading.jl:1038
 [11] include(::Module, ::String) at ./sysimg.jl:29
 [12] include(::String) at ./client.jl:403
 [13] top-level scope at none:0
in expression starting at /root/gen_users.jl:175

请帮我解决这个问题

您能否将示例简化为2-3列,以满足MWE Stackoverflow指南的要求。您能否将示例简化为2-3列,以满足MWE Stackoverflow指南的要求。