CopyFrom uses the PostgreSQL copy protocol to perform bulk data insertion. It returns the number of rows copied and an error. CopyFrom requires all values use the binary format. A pgtype.Type that supports the binary format must be registered for the type of each column. Almost all types implemente
(ctx context.Context, tableName Identifier, columnNames []string, rowSrc CopyFromSource)
| 263 | // Even though enum types appear to be strings they still must be registered to use with [Conn.CopyFrom]. This can be done with |
| 264 | // [Conn.LoadType] and [pgtype.Map.RegisterType]. |
| 265 | func (c *Conn) CopyFrom(ctx context.Context, tableName Identifier, columnNames []string, rowSrc CopyFromSource) (int64, error) { |
| 266 | ct := ©From{ |
| 267 | conn: c, |
| 268 | tableName: tableName, |
| 269 | columnNames: columnNames, |
| 270 | rowSrc: rowSrc, |
| 271 | readerErrChan: make(chan error), |
| 272 | mode: c.config.DefaultQueryExecMode, |
| 273 | } |
| 274 | |
| 275 | return ct.run(ctx) |
| 276 | } |