linux - how to execute postgresql function with unnest array as parameter using libpqxx c++ -
i have created postgresql function,
create or replace function check4(interval_ int[],password_ text[]) returns void $$ begin execute ' insert test(id,password) select unnest($1),unnest($2)' using $1,$2; end; $$ language plpgsql;
then tried execute above procedure c++ using libpqxx
try { connection *conn; conn = new connection("dbname = test user = postgres password = postgres hostaddr = 127.0.0.1 port = 5432"); if (conn->is_open()) { cout<<"opened database successfully:"<<std::endl<<std::flush; } else { cout << "can't open database" << std::endl << std::flush; } int arr_id[2] = { 1,2 }; string arr_pass[2] = { "hi","bye" }; work p(*conn); conn->prepare("example", "select check4(unnest(:$1), unnest(:$2));"); (int = 0; < 2; i++) { p.prepared("example")(arr_id[i])(arr_pass[i]).exec(); } p.commit(); cout << "records created successfully" << endl; } catch (const std::exception &e) { cerr << e.what() << std::endl; }
in code, data inserted 1 one want data inserted in bulk.i want create array of 5000 records , insert in 1 shot.
please suggest me, how pass array parameter function? appreciated.
thank you.
Comments
Post a Comment