This allows for connection settings to be updated without having to create
a new pool. The callback is passed a copy of the pgx.ConnConfig and will
not impact existing live connections.
Using CopyFromRows can often be inconvenient to use, because you would
need to convert a typed array to an [][]interface{}. Similarly,
implementing a custom CopyFromSource is too verbose for one-off things.
Add CopyFromSlice that allows to more easily convert a slice to a
CopyFromSource. Example:
copyCount, err := conn.CopyFrom(
context.Background(),
pgx.Identifier{"people"},
[]string{"first_name", "last_name", "age"},
pgx.CopyFromSlice(len(rows), func(i int) ([]interface{}, error) {
return []interface{user.FirstName, user.LastName, user.Age}, nil
}),
)
This patch fixes jackc/pgx#841. The meat of the fix lives
in [a PR to the pgconn repo][1]. This change just checks
for errors after executing a prepared statement and informs
the underlying stmtcache about them so that it can properly
clean up. We don't try to get fancy with retries or anything
like that, just return the error and allow the application to handle it.
I had to make [some][1] [changes][2] to to the jackc/pgconn package as well
as this package.
Fixes#841
[1]: https://github.com/jackc/pgconn/pull/56
[2]: https://github.com/jackc/pgconn/pull/55
This patch adds a new StatementErrored method to the stmtcache.
This routine MUST be called by users of the cache whenever the
execution of a statement results in an error. This will allow
the cache to make an intelligent decision about whether or not
the statement needs to be purged from the cache.
Original issue https://github.com/jackc/pgtype/issues/68
This crash occurred in the recursive assignment system used to support
multidimensional arrays.
This was fixed in 9639a69d451f55456f598c1aa8b93053f8df3088. However,
that fix incorrectly used nil instead of an empty slice.
In hindsight, it appears the fundamental error is that an assignment to
a slice of a type that is not specified is handled with the recursive /
reflection path. Or another way of looking at it is as an unexpected
feature where []T can now be scanned if individual elements are
assignable to T even if []T is not specifically handled.
But this new reflection / recursive path did not handle empty arrays.
This fix handles the reflection path for an empty slice by allocating an
empty slice.
There were 2 errors when using the example code:
- not enough arguments in call to pgConn.Close
- no new variables on left side of :=
With these changes, the example works again.