CHANGELOG.md (15415B)
1 # 5.4.1 (June 18, 2023) 2 3 * Fix: concurrency bug with pgtypeDefaultMap and simple protocol (Lev Zakharov) 4 * Add TxOptions.BeginQuery to allow overriding the default BEGIN query 5 6 # 5.4.0 (June 14, 2023) 7 8 * Replace platform specific syscalls for non-blocking IO with more traditional goroutines and deadlines. This returns to the v4 approach with some additional improvements and fixes. This restores the ability to use a pgx.Conn over an ssh.Conn as well as other non-TCP or Unix socket connections. In addition, it is a significantly simpler implementation that is less likely to have cross platform issues. 9 * Optimization: The default type registrations are now shared among all connections. This saves about 100KB of memory per connection. `pgtype.Type` and `pgtype.Codec` values are now required to be immutable after registration. This was already necessary in most cases but wasn't documented until now. (Lev Zakharov) 10 * Fix: Ensure pgxpool.Pool.QueryRow.Scan releases connection on panic 11 * CancelRequest: don't try to read the reply (Nicola Murino) 12 * Fix: correctly handle bool type aliases (Wichert Akkerman) 13 * Fix: pgconn.CancelRequest: Fix unix sockets: don't use RemoteAddr() 14 * Fix: pgx.Conn memory leak with prepared statement caching (Evan Jones) 15 * Add BeforeClose to pgxpool.Pool (Evan Cordell) 16 * Fix: various hstore fixes and optimizations (Evan Jones) 17 * Fix: RowToStructByPos with embedded unexported struct 18 * Support different bool string representations (Lev Zakharov) 19 * Fix: error when using BatchResults.Exec on a select that returns an error after some rows. 20 * Fix: pipelineBatchResults.Exec() not returning error from ResultReader 21 * Fix: pipeline batch results not closing pipeline when error occurs while reading directly from results instead of using 22 a callback. 23 * Fix: scanning a table type into a struct 24 * Fix: scan array of record to pointer to slice of struct 25 * Fix: handle null for json (Cemre Mengu) 26 * Batch Query callback is called even when there is an error 27 * Add RowTo(AddrOf)StructByNameLax (Audi P. Risa P) 28 29 # 5.3.1 (February 27, 2023) 30 31 * Fix: Support v4 and v5 stdlib in same program (Tomáš Procházka) 32 * Fix: sql.Scanner not being used in certain cases 33 * Add text format jsonpath support 34 * Fix: fake non-blocking read adaptive wait time 35 36 # 5.3.0 (February 11, 2023) 37 38 * Fix: json values work with sql.Scanner 39 * Fixed / improved error messages (Mark Chambers and Yevgeny Pats) 40 * Fix: support scan into single dimensional arrays 41 * Fix: MaxConnLifetimeJitter setting actually jitter (Ben Weintraub) 42 * Fix: driver.Value representation of bytea should be []byte not string 43 * Fix: better handling of unregistered OIDs 44 * CopyFrom can use query cache to avoid extra round trip to get OIDs (Alejandro Do Nascimento Mora) 45 * Fix: encode to json ignoring driver.Valuer 46 * Support sql.Scanner on renamed base type 47 * Fix: pgtype.Numeric text encoding of negative numbers (Mark Chambers) 48 * Fix: connect with multiple hostnames when one can't be resolved 49 * Upgrade puddle to remove dependency on uber/atomic and fix alignment issue on 32-bit platform 50 * Fix: scanning json column into **string 51 * Multiple reductions in memory allocations 52 * Fake non-blocking read adapts its max wait time 53 * Improve CopyFrom performance and reduce memory usage 54 * Fix: encode []any to array 55 * Fix: LoadType for composite with dropped attributes (Felix Röhrich) 56 * Support v4 and v5 stdlib in same program 57 * Fix: text format array decoding with string of "NULL" 58 * Prefer binary format for arrays 59 60 # 5.2.0 (December 5, 2022) 61 62 * `tracelog.TraceLog` implements the pgx.PrepareTracer interface. (Vitalii Solodilov) 63 * Optimize creating begin transaction SQL string (Petr Evdokimov and ksco) 64 * `Conn.LoadType` supports range and multirange types (Vitalii Solodilov) 65 * Fix scan `uint` and `uint64` `ScanNumeric`. This resolves a PostgreSQL `numeric` being incorrectly scanned into `uint` and `uint64`. 66 67 # 5.1.1 (November 17, 2022) 68 69 * Fix simple query sanitizer where query text contains a Unicode replacement character. 70 * Remove erroneous `name` argument from `DeallocateAll()`. Technically, this is a breaking change, but given that method was only added 5 days ago this change was accepted. (Bodo Kaiser) 71 72 # 5.1.0 (November 12, 2022) 73 74 * Update puddle to v2.1.2. This resolves a race condition and a deadlock in pgxpool. 75 * `QueryRewriter.RewriteQuery` now returns an error. Technically, this is a breaking change for any external implementers, but given the minimal likelihood that there are actually any external implementers this change was accepted. 76 * Expose `GetSSLPassword` support to pgx. 77 * Fix encode `ErrorResponse` unknown field handling. This would only affect pgproto3 being used directly as a proxy with a non-PostgreSQL server that included additional error fields. 78 * Fix date text format encoding with 5 digit years. 79 * Fix date values passed to a `sql.Scanner` as `string` instead of `time.Time`. 80 * DateCodec.DecodeValue can return `pgtype.InfinityModifier` instead of `string` for infinite values. This now matches the behavior of the timestamp types. 81 * Add domain type support to `Conn.LoadType()`. 82 * Add `RowToStructByName` and `RowToAddrOfStructByName`. (Pavlo Golub) 83 * Add `Conn.DeallocateAll()` to clear all prepared statements including the statement cache. (Bodo Kaiser) 84 85 # 5.0.4 (October 24, 2022) 86 87 * Fix: CollectOneRow prefers PostgreSQL error over pgx.ErrorNoRows 88 * Fix: some reflect Kind checks to first check for nil 89 * Bump golang.org/x/text dependency to placate snyk 90 * Fix: RowToStructByPos on structs with multiple anonymous sub-structs (Baptiste Fontaine) 91 * Fix: Exec checks if tx is closed 92 93 # 5.0.3 (October 14, 2022) 94 95 * Fix `driver.Valuer` handling edge cases that could cause infinite loop or crash 96 97 # v5.0.2 (October 8, 2022) 98 99 * Fix date encoding in text format to always use 2 digits for month and day 100 * Prefer driver.Valuer over wrap plans when encoding 101 * Fix scan to pointer to pointer to renamed type 102 * Allow scanning NULL even if PG and Go types are incompatible 103 104 # v5.0.1 (September 24, 2022) 105 106 * Fix 32-bit atomic usage 107 * Add MarshalJSON for Float8 (yogipristiawan) 108 * Add `[` and `]` to text encoding of `Lseg` 109 * Fix sqlScannerWrapper NULL handling 110 111 # v5.0.0 (September 17, 2022) 112 113 ## Merged Packages 114 115 `github.com/jackc/pgtype`, `github.com/jackc/pgconn`, and `github.com/jackc/pgproto3` are now included in the main 116 `github.com/jackc/pgx` repository. Previously there was confusion as to where issues should be reported, additional 117 release work due to releasing multiple packages, and less clear changelogs. 118 119 ## pgconn 120 121 `CommandTag` is now an opaque type instead of directly exposing an underlying `[]byte`. 122 123 The return value `ResultReader.Values()` is no longer safe to retain a reference to after a subsequent call to `NextRow()` or `Close()`. 124 125 `Trace()` method adds low level message tracing similar to the `PQtrace` function in `libpq`. 126 127 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. 128 129 `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. 130 131 pgconn now supports pipeline mode. 132 133 `*PgConn.ReceiveResults` removed. Use pipeline mode instead. 134 135 `Timeout()` no longer considers `context.Canceled` as a timeout error. `context.DeadlineExceeded` still is considered a timeout error. 136 137 ## pgxpool 138 139 `Connect` and `ConnectConfig` have been renamed to `New` and `NewWithConfig` respectively. The `LazyConnect` option has been removed. Pools always lazily connect. 140 141 ## pgtype 142 143 The `pgtype` package has been significantly changed. 144 145 ### NULL Representation 146 147 Previously, types had a `Status` field that could be `Undefined`, `Null`, or `Present`. This has been changed to a 148 `Valid` `bool` field to harmonize with how `database/sql` represents `NULL` and to make the zero value useable. 149 150 Previously, a type that implemented `driver.Valuer` would have the `Value` method called even on a nil pointer. All nils 151 whether typed or untyped now represent `NULL`. 152 153 ### Codec and Value Split 154 155 Previously, the type system combined decoding and encoding values with the value types. e.g. Type `Int8` both handled 156 encoding and decoding the PostgreSQL representation and acted as a value object. This caused some difficulties when 157 there was not an exact 1 to 1 relationship between the Go types and the PostgreSQL types For example, scanning a 158 PostgreSQL binary `numeric` into a Go `float64` was awkward (see https://github.com/jackc/pgtype/issues/147). This 159 concepts have been separated. A `Codec` only has responsibility for encoding and decoding values. Value types are 160 generally defined by implementing an interface that a particular `Codec` understands (e.g. `PointScanner` and 161 `PointValuer` for the PostgreSQL `point` type). 162 163 ### Array Types 164 165 All array types are now handled by `ArrayCodec` instead of using code generation for each new array type. This also 166 means that less common array types such as `point[]` are now supported. `Array[T]` supports PostgreSQL multi-dimensional 167 arrays. 168 169 ### Composite Types 170 171 Composite types must be registered before use. `CompositeFields` may still be used to construct and destruct composite 172 values, but any type may now implement `CompositeIndexGetter` and `CompositeIndexScanner` to be used as a composite. 173 174 ### Range Types 175 176 Range types are now handled with types `RangeCodec` and `Range[T]`. This allows additional user defined range types to 177 easily be handled. Multirange types are handled similarly with `MultirangeCodec` and `Multirange[T]`. 178 179 ### pgxtype 180 181 `LoadDataType` moved to `*Conn` as `LoadType`. 182 183 ### Bytea 184 185 The `Bytea` and `GenericBinary` types have been replaced. Use the following instead: 186 187 * `[]byte` - For normal usage directly use `[]byte`. 188 * `DriverBytes` - Uses driver memory only available until next database method call. Avoids a copy and an allocation. 189 * `PreallocBytes` - Uses preallocated byte slice to avoid an allocation. 190 * `UndecodedBytes` - Avoids any decoding. Allows working with raw bytes. 191 192 ### Dropped lib/pq Support 193 194 `pgtype` previously supported and was tested against [lib/pq](https://github.com/lib/pq). While it will continue to work 195 in most cases this is no longer supported. 196 197 ### database/sql Scan 198 199 Previously, most `Scan` implementations would convert `[]byte` to `string` automatically to decode a text value. Now 200 only `string` is handled. This is to allow the possibility of future binary support in `database/sql` mode by 201 considering `[]byte` to be binary format and `string` text format. This change should have no effect for any use with 202 `pgx`. The previous behavior was only necessary for `lib/pq` compatibility. 203 204 Added `*Map.SQLScanner` to create a `sql.Scanner` for types such as `[]int32` and `Range[T]` that do not implement 205 `sql.Scanner` directly. 206 207 ### Number Type Fields Include Bit size 208 209 `Int2`, `Int4`, `Int8`, `Float4`, `Float8`, and `Uint32` fields now include bit size. e.g. `Int` is renamed to `Int64`. 210 This matches the convention set by `database/sql`. In addition, for comparable types like `pgtype.Int8` and 211 `sql.NullInt64` the structures are identical. This means they can be directly converted one to another. 212 213 ### 3rd Party Type Integrations 214 215 * Extracted integrations with https://github.com/shopspring/decimal and https://github.com/gofrs/uuid to 216 https://github.com/jackc/pgx-shopspring-decimal and https://github.com/jackc/pgx-gofrs-uuid respectively. This trims 217 the pgx dependency tree. 218 219 ### Other Changes 220 221 * `Bit` and `Varbit` are both replaced by the `Bits` type. 222 * `CID`, `OID`, `OIDValue`, and `XID` are replaced by the `Uint32` type. 223 * `Hstore` is now defined as `map[string]*string`. 224 * `JSON` and `JSONB` types removed. Use `[]byte` or `string` directly. 225 * `QChar` type removed. Use `rune` or `byte` directly. 226 * `Inet` and `Cidr` types removed. Use `netip.Addr` and `netip.Prefix` directly. These types are more memory efficient than the previous `net.IPNet`. 227 * `Macaddr` type removed. Use `net.HardwareAddr` directly. 228 * Renamed `pgtype.ConnInfo` to `pgtype.Map`. 229 * Renamed `pgtype.DataType` to `pgtype.Type`. 230 * Renamed `pgtype.None` to `pgtype.Finite`. 231 * `RegisterType` now accepts a `*Type` instead of `Type`. 232 * Assorted array helper methods and types made private. 233 234 ## stdlib 235 236 * Removed `AcquireConn` and `ReleaseConn` as that functionality has been built in since Go 1.13. 237 238 ## Reduced Memory Usage by Reusing Read Buffers 239 240 Previously, the connection read buffer would allocate large chunks of memory and never reuse them. This allowed 241 transferring ownership to anything such as scanned values without incurring an additional allocation and memory copy. 242 However, this came at the cost of overall increased memory allocation size. But worse it was also possible to pin large 243 chunks of memory by retaining a reference to a small value that originally came directly from the read buffer. Now 244 ownership remains with the read buffer and anything needing to retain a value must make a copy. 245 246 ## Query Execution Modes 247 248 Control over automatic prepared statement caching and simple protocol use are now combined into query execution mode. 249 See documentation for `QueryExecMode`. 250 251 ## QueryRewriter Interface and NamedArgs 252 253 pgx now supports named arguments with the `NamedArgs` type. This is implemented via the new `QueryRewriter` interface which 254 allows arbitrary rewriting of query SQL and arguments. 255 256 ## RowScanner Interface 257 258 The `RowScanner` interface allows a single argument to Rows.Scan to scan the entire row. 259 260 ## Rows Result Helpers 261 262 * `CollectRows` and `RowTo*` functions simplify collecting results into a slice. 263 * `CollectOneRow` collects one row using `RowTo*` functions. 264 * `ForEachRow` simplifies scanning each row and executing code using the scanned values. `ForEachRow` replaces `QueryFunc`. 265 266 ## Tx Helpers 267 268 Rather than every type that implemented `Begin` or `BeginTx` methods also needing to implement `BeginFunc` and 269 `BeginTxFunc` these methods have been converted to functions that take a db that implements `Begin` or `BeginTx`. 270 271 ## Improved Batch Query Ergonomics 272 273 Previously, the code for building a batch went in one place before the call to `SendBatch`, and the code for reading the 274 results went in one place after the call to `SendBatch`. This could make it difficult to match up the query and the code 275 to handle the results. Now `Queue` returns a `QueuedQuery` which has methods `Query`, `QueryRow`, and `Exec` which can 276 be used to register a callback function that will handle the result. Callback functions are called automatically when 277 `BatchResults.Close` is called. 278 279 ## SendBatch Uses Pipeline Mode When Appropriate 280 281 Previously, a batch with 10 unique parameterized statements executed 100 times would entail 11 network round trips. 1 282 for each prepare / describe and 1 for executing them all. Now pipeline mode is used to prepare / describe all statements 283 in a single network round trip. So it would only take 2 round trips. 284 285 ## Tracing and Logging 286 287 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. 288 289 All integrations with 3rd party loggers have been extracted to separate repositories. This trims the pgx dependency 290 tree.