2
0

Add CopyTo to support PostgreSQL copy protocol

fixes #102
This commit is contained in:
Jack Christensen
2016-08-10 16:27:44 -05:00
parent bb73d84279
commit 5f7d01778e
9 changed files with 991 additions and 0 deletions
+20
View File
@@ -104,6 +104,26 @@ creates a transaction with a specified isolation level.
return err
}
Copy Protocol
Use CopyTo to efficiently insert multiple rows at a time using the PostgreSQL
copy protocol. CopyTo accepts a CopyToSource interface. If the data is already
in a [][]interface{} use CopyToRows to wrap it in a CopyToSource interface. Or
implement CopyToSource to avoid buffering the entire data set in memory.
rows := [][]interface{}{
{"John", "Smith", int32(36)},
{"Jane", "Doe", int32(29)},
}
copyCount, err := conn.CopyTo(
"people",
[]string{"first_name", "last_name", "age"},
pgx.CopyToRows(rows),
)
CopyTo can be faster than an insert with as few as 5 rows.
Listen and Notify
pgx can listen to the PostgreSQL notification system with the