Answer the question
In order to leave comments, you need to log in
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
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 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 questionAsk a Question
731 491 924 answers to any question