Bulk inserts with epgsqli:equery/3?

145 views
Skip to first unread message

stra...@gmail.com

unread,
Jun 24, 2016, 12:35:47 PM6/24/16
to Erlang epgsql Postgres driver use and development
Is there a way to do bulk inserts with epgsqli:equery/3? I'd like to insert sets of records into a single table in the database. Looking at the readme I see it's possible to do batch execution of statements. I want to execute one statement with multiple sets of parameters. Is this possible? The query I want to execute looks something like this:

INSERT INTO table (col1, col2)
VALUES
(row, 1),
(row, 2);

I know I can do this with epgsql:squery/2, so if this isn't possible it won't be problematic. I'm just curious if this is supported.

Thank you,

Trevor

Sergey Prokhorov

unread,
Jun 26, 2016, 5:27:12 AM6/26/16
to Erlang epgsql Postgres driver use and development, stra...@gmail.com
You may be interested in execute_batch https://github.com/epgsql/epgsql#batch-execution and prepared_query https://github.com/epgsql/epgsql#prepared-query

equery is not very eficient for batch/bulk loading.

пятница, 24 июня 2016 г., 19:35:47 UTC+3 пользователь stra...@gmail.com написал:

led...@gmail.com

unread,
Mar 31, 2017, 1:22:33 PM3/31/17
to Erlang epgsql Postgres driver use and development
epgsql:equery(Db,
"INSERT INTO table
(col1, col2)
SELECT row, UNNEST($1::INTEGER[])",
[[1,2]]).
Reply all
Reply to author
Forward
0 new messages