Changelog History
Page 1
-
v5.0.4 Changes
October 24, 2022- π Fix: CollectOneRow prefers PostgreSQL error over pgx.ErrorNoRows
- π Fix: some reflect Kind checks to first check for nil
- β¬οΈ Bump golang.org/x/text dependency to placate snyk
- π Fix: RowToStructByPos on structs with multiple anonymous sub-structs (Baptiste Fontaine)
- π Fix: Exec checks if tx is closed
-
v5.0.3 Changes
October 14, 2022- π Fix
driver.Valuer
handling edge cases that could cause infinite loop or crash
- π Fix
-
v5.0.2 Changes
October 08, 2022- π Fix date encoding in text format to always use 2 digits for month and day
- Prefer driver.Valuer over wrap plans when encoding
- π Fix scan to pointer to pointer to renamed type
- π Allow scanning NULL even if PG and Go types are incompatible
-
v5.0.1 Changes
September 24, 2022- π Fix 32-bit atomic usage
- β Add MarshalJSON for Float8 (yogipristiawan)
- β Add
[
and]
to text encoding ofLseg
- π Fix sqlScannerWrapper NULL handling
-
v5.0.0 Changes
September 17, 2022π¦ Merged Packages
github.com/jackc/pgtype
,github.com/jackc/pgconn
, andgithub.com/jackc/pgproto3
are now included in the maingithub.com/jackc/pgx
repository. Previously there was confusion as to where issues should be reported, additional π release work due to releasing multiple packages, and less clear changelogs.pgconn
CommandTag
is now an opaque type instead of directly exposing an underlying[]byte
.The return value
ResultReader.Values()
is no longer safe to retain a reference to after a subsequent call toNextRow()
orClose()
.Trace()
method adds low level message tracing similar to thePQtrace
function inlibpq
.pgconn now uses non-blocking IO. This is a significant internal restructuring, but it should not cause any visible changes on its own. However, it is important in implementing other new features.
CheckConn()
checks a connection's liveness by doing a non-blocking read. This can be used to detect database restarts or network interruptions without executing a query or a ping.π pgconn now supports pipeline mode.
π
*PgConn.ReceiveResults
removed. Use pipeline mode instead.β±
Timeout()
no longer considerscontext.Canceled
as a timeout error.context.DeadlineExceeded
still is considered a timeout error.pgxpool
π
Connect
andConnectConfig
have been renamed toNew
andNewWithConfig
respectively. TheLazyConnect
option has been removed. Pools always lazily connect.pgtype
π¦ The
pgtype
package has been significantly changed.NULL Representation
Previously, types had a
Status
field that could beUndefined
,Null
, orPresent
. This has been changed to aValid
bool
field to harmonize with howdatabase/sql
representsNULL
and to make the zero value useable.Codec and Value Split
Previously, the type system combined decoding and encoding values with the value types. e.g. Type
Int8
both handled encoding and decoding the PostgreSQL representation and acted as a value object. This caused some difficulties when there was not an exact 1 to 1 relationship between the Go types and the PostgreSQL types For example, scanning a π PostgreSQL binarynumeric
into a Gofloat64
was awkward (see https://github.com/jackc/pgtype/issues/147). This concepts have been separated. ACodec
only has responsibility for encoding and decoding values. Value types are generally defined by implementing an interface that a particularCodec
understands (e.g.PointScanner
andPointValuer
for the PostgreSQLpoint
type).Array Types
All array types are now handled by
ArrayCodec
instead of using code generation for each new array type. This also π means that less common array types such aspoint[]
are now supported.Array[T]
supports PostgreSQL multi-dimensional arrays.Composite Types
Composite types must be registered before use.
CompositeFields
may still be used to construct and destruct composite values, but any type may now implementCompositeIndexGetter
andCompositeIndexScanner
to be used as a composite.Range Types
Range types are now handled with types
RangeCodec
andRange[T]
. This allows additional user defined range types to easily be handled. Multirange types are handled similarly withMultirangeCodec
andMultirange[T]
.pgxtype
π
LoadDataType
moved to*Conn
asLoadType
.Bytea
The
Bytea
andGenericBinary
types have been replaced. Use the following instead:[]byte
- For normal usage directly use[]byte
.DriverBytes
- Uses driver memory only available until next database method call. Avoids a copy and an allocation.PreallocBytes
- Uses preallocated byte slice to avoid an allocation.UndecodedBytes
- Avoids any decoding. Allows working with raw bytes.
β¬οΈ Dropped lib/pq Support
β
pgtype
previously supported and was tested against lib/pq. While it will continue to work π in most cases this is no longer supported.database/sql Scan
Previously, most
Scan
implementations would convert[]byte
tostring
automatically to decode a text value. Now π onlystring
is handled. This is to allow the possibility of future binary support indatabase/sql
mode by considering[]byte
to be binary format andstring
text format. This change should have no effect for any use withpgx
. The previous behavior was only necessary forlib/pq
compatibility.β Added
*Map.SQLScanner
to create asql.Scanner
for types such as[]int32
andRange[T]
that do not implementsql.Scanner
directly.Number Type Fields Include Bit size
Int2
,Int4
,Int8
,Float4
,Float8
, andUint32
fields now include bit size. e.g.Int
is renamed toInt64
. This matches the convention set bydatabase/sql
. In addition, for comparable types likepgtype.Int8
and πsql.NullInt64
the structures are identical. This means they can be directly converted one to another.3rd Party Type Integrations
- Extracted integrations with https://github.com/shopspring/decimal and https://github.com/gofrs/uuid to https://github.com/jackc/pgx-shopspring-decimal and https://github.com/jackc/pgx-gofrs-uuid respectively. This trims the pgx dependency tree.
Other Changes
Bit
andVarbit
are both replaced by theBits
type.CID
,OID
,OIDValue
, andXID
are replaced by theUint32
type.Hstore
is now defined asmap[string]*string
.- π
JSON
andJSONB
types removed. Use[]byte
orstring
directly. - π
QChar
type removed. Userune
orbyte
directly. - π
Inet
andCidr
types removed. Usenetip.Addr
andnetip.Prefix
directly. These types are more memory efficient than the previousnet.IPNet
. - π
Macaddr
type removed. Usenet.HardwareAddr
directly. - π Renamed
pgtype.ConnInfo
topgtype.Map
. - π Renamed
pgtype.DataType
topgtype.Type
. - π Renamed
pgtype.None
topgtype.Finite
. RegisterType
now accepts a*Type
instead ofType
.- Assorted array helper methods and types made private.
stdlib
- β Removed
AcquireConn
andReleaseConn
as that functionality has been built in since Go 1.13.
β¬οΈ Reduced Memory Usage by Reusing Read Buffers
Previously, the connection read buffer would allocate large chunks of memory and never reuse them. This allowed transferring ownership to anything such as scanned values without incurring an additional allocation and memory copy. π However, this came at the cost of overall increased memory allocation size. But worse it was also possible to pin large chunks of memory by retaining a reference to a small value that originally came directly from the read buffer. Now ownership remains with the read buffer and anything needing to retain a value must make a copy.
Query Execution Modes
Control over automatic prepared statement caching and simple protocol use are now combined into query execution mode. π See documentation for
QueryExecMode
.QueryRewriter Interface and NamedArgs
π pgx now supports named arguments with the
NamedArgs
type. This is implemented via the newQueryRewriter
interface which π allows arbitrary rewriting of query SQL and arguments.RowScanner Interface
The
RowScanner
interface allows a single argument to Rows.Scan to scan the entire row.Rows Result Helpers
CollectRows
andRowTo*
functions simplify collecting results into a slice.CollectOneRow
collects one row usingRowTo*
functions.ForEachRow
simplifies scanning each row and executing code using the scanned values.ForEachRow
replacesQueryFunc
.
Tx Helpers
Rather than every type that implemented
Begin
orBeginTx
methods also needing to implementBeginFunc
andBeginTxFunc
these methods have been converted to functions that take a db that implementsBegin
orBeginTx
.π Improved Batch Query Ergonomics
π Previously, the code for building a batch went in one place before the call to
SendBatch
, and the code for reading the results went in one place after the call toSendBatch
. This could make it difficult to match up the query and the code to handle the results. NowQueue
returns aQueuedQuery
which has methodsQuery
,QueryRow
, andExec
which can be used to register a callback function that will handle the result. Callback functions are called automatically whenBatchResults.Close
is called.SendBatch Uses Pipeline Mode When Appropriate
Previously, a batch with 10 unique parameterized statements executed 100 times would entail 11 network round trips. 1 for each prepare / describe and 1 for executing them all. Now pipeline mode is used to prepare / describe all statements in a single network round trip. So it would only take 2 round trips.
π² Tracing and Logging
π¦ Internal logging support has been replaced with tracing hooks. This allows custom tracing integration with tools like OpenTelemetry. Package tracelog provides an adapter for pgx v4 loggers to act as a tracer.
All integrations with 3rd party loggers have been extracted to separate repositories. This trims the pgx dependency tree.
-
v4.16.1 Changes
May 07, 2022- β¬οΈ Upgrade pgconn to v1.12.1
- π Fix explicitly prepared statements with describe statement cache mode
-
v4.16.0 Changes
April 21, 2022- β¬οΈ Upgrade pgconn to v1.12.0
- β¬οΈ Upgrade pgproto3 to v2.3.0
- β¬οΈ Upgrade pgtype to v1.11.0
- π Fix: Do not panic when context cancelled while getting statement from cache.
- π Fix: Less memory pinning from old Rows.
- π Fix: Support '\r' line ending when sanitizing SQL comment.
- β Add pluggable GSSAPI support (Oliver Tan)
-
v4.15.0 Changes
February 07, 2022- β¬οΈ Upgrade to pgconn v1.11.0
- β¬οΈ Upgrade to pgtype v1.10.0
- β¬οΈ Upgrade puddle to v1.2.1
- π Make BatchResults.Close safe to be called multiple times
-
v4.14.1 Changes
November 28, 2021- β¬οΈ Upgrade pgtype to v1.9.1 (fixes unintentional change to timestamp binary decoding)
- Start pgxpool background health check after initial connections
-
v4.14.0 Changes
November 20, 2021- β¬οΈ Upgrade pgconn to v1.10.1
- β¬οΈ Upgrade pgproto3 to v2.2.0
- β¬οΈ Upgrade pgtype to v1.9.0
- β¬οΈ Upgrade puddle to v1.2.0
- β Add QueryFunc to BatchResults
- β Add context options to zerologadapter (Thomas FrΓΆssman)
- β Add zerologadapter.NewContextLogger (urso)
- Eager initialize minpoolsize on connect (Daniel)
- Unpin memory used by large queries immediately after use