A
A
Alexander Vladimirovich2018-12-19 15:28:16
PostgreSQL
Alexander Vladimirovich, 2018-12-19 15:28:16

How to batch insert data into a table without string concatenation?

Greetings!
there is a table order_product_link
field order_id int product_id int
insert into order_product_link (order_id, product_id) values ​​(1, 1),(1, 2),(1, 3)...(1, 100500)
order_id is the same for all records, product_id is different
the data to be inserted is in the array []int64

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Melkij, 2018-12-19
@melkij

For example,
How to transfer an array from go to a postgresql array - I will not tell you. Check with the go library you are using.
Or copy from stdin and send as many lines to copy as needed.

A
Alexey, 2018-12-25
@Shark13

A description of batch insert without concatenation is in the postgres driver documentation with an example
https://godoc.org/github.com/lib/pq#hdr-Bulk_imports
On the plus side, this is the fastest way to insert a data batch into postgres from code, faster than import

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question