-
Is optimal way for insert multiple rows into a table using a single statement is this way?
Or better use some another way? Maybe exists some method or function? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
The COPY protocol is the fastest way to insert many rows at a time. https://pkg.go.dev/github.com/jackc/pgx/[email protected]#hdr-Copy_Protocol Next in speed would be one insert statement with multiple rows as you have above. That is a little awkward to use because you have to build the SQL. You also are limited to ~64k parameters. A batch operation that bundles bunch of simple inserts together would be next in performance. https://pkg.go.dev/github.com/jackc/pgx/[email protected]#Conn.SendBatch And slowest, of course, would be inserting each row one at a time. |
Beta Was this translation helpful? Give feedback.
The COPY protocol is the fastest way to insert many rows at a time. https://pkg.go.dev/github.com/jackc/pgx/[email protected]#hdr-Copy_Protocol
Next in speed would be one insert statement with multiple rows as you have above. That is a little awkward to use because you have to build the SQL. You also are limited to ~64k parameters.
A batch operation that bundles bunch of simple inserts together would be next in performance. https://pkg.go.dev/github.com/jackc/pgx/[email protected]#Conn.SendBatch
And slowest, of course, would be inserting each row one at a time.