496 Commits

Author SHA1 Message Date
Pavlo Golub
33163eefca fix documentation links 2025-06-12 16:01:14 +02:00
Jack Christensen
1d557f9116 Remove PlanScan memoization
Previously, PlanScan used a cache to improve performance. However, the
cache could get confused in certain cases. For example, the following
would fail:

m := pgtype.NewMap()
var err error

var tags any
err = m.Scan(pgtype.TextArrayOID, pgx.TextFormatCode, []byte("{foo,bar,baz}"), &tags)
require.NoError(t, err)

var cells [][]string
err = m.Scan(pgtype.TextArrayOID, pgx.TextFormatCode, []byte("{{foo,bar},{baz,quz}}"), &cells)
require.NoError(t, err)

This commit removes the memoization and adds a test to ensure that this
case works.

The benchmarks were also updated to include an array of strings to
ensure this path is benchmarked. As it turned out, there was next to no
performance difference between the cached and non-cached versions.

It's possible there may be a performance impact in certain complicated
cases, but I have not encountered any. If there are any performance
issues, we can optimize the narrower case rather than adding memoization
everywhere.
2025-05-17 16:34:01 -05:00
Jack Christensen
de7fe81d78 Use reflect.TypeFor instead of reflect.TypeOf
Simplified function became available in Go 1.22.
2025-05-17 09:11:31 -05:00
Jack Christensen
d9eb089bd7 Remove unused function 2025-05-17 09:09:07 -05:00
Jack Christensen
6be24eb08d Fix comment typo 2025-05-17 09:01:55 -05:00
Felix Röhrich
63422c7d6c revert change in if 2025-03-24 15:01:50 +01:00
Jack Christensen
6bf1b0b1b9 Add database/sql to overview of scanning 2025-02-22 08:42:26 -06:00
Jack Christensen
14bda65a0c Correct pgtype docs 2025-02-22 08:34:31 -06:00
Jack Christensen
dcb7193669
Merge pull request #2236 from felix-roehrich/fr/fix-plan-scan
Alternative implementation for JSONCodec.PlanScan
2025-01-25 08:56:38 -06:00
Jack Christensen
b5efc90a32
Merge pull request #2028 from jackc/enable-composite-tests-on-cockroachdb
Enable composite tests on cockroachdb
2025-01-25 08:22:32 -06:00
Jack Christensen
a26c93551f Skip TestCompositeCodecTranscodeStructWrapperForTable 2025-01-25 08:15:40 -06:00
Jack Christensen
2d21a2b80d
Merge pull request #2228 from jackc/fix-xml-decode-value
XMLCodec: fix DecodeValue to return a []byte
2025-01-25 07:24:30 -06:00
Felix Röhrich
a5353af354 rework JSONCodec.PlanScan 2025-01-22 22:35:35 +01:00
Jack Christensen
0bc29e3000
Merge pull request #2225 from logicbomb/improve-error-message
Include the field name in error messages when scanning structs
2025-01-18 10:41:13 -06:00
Jason Turim
9c0ad690a9 Include the field name in error messages when scanning structs 2025-01-11 14:31:24 -05:00
Jack Christensen
03f08abda3 Fix in Unmarshal function rather than DecodeValue
This preserves backwards compatibility in the unlikely event someone is
using an alternative XML unmarshaler that does support unmarshalling
into *any.
2025-01-11 11:26:46 -06:00
Jack Christensen
329cb45913 XMLCodec: fix DecodeValue to return a []byte
Previously, DecodeValue would always return nil with the default
Unmarshal function.

fixes https://github.com/jackc/pgx/issues/2227
2025-01-11 10:55:48 -06:00
Phil Constantinou
3c640a44b6 Making the tests a little cleaner and clear 2025-01-06 09:24:55 -08:00
Phil Constantinou
5424d3c873 Return error and make sure they are unit tested 2025-01-05 19:45:45 -08:00
Phil Constantinou
42d3d00734 Parse as a UTC time 2025-01-05 19:19:17 -08:00
Phil Constantinou
cdc672cf3f Make JSON output confirm to ISO8601 timestamp without a timezone 2025-01-05 13:05:51 -08:00
Phil Constantinou
52e2858629 Added unit test and fixed typo 2025-01-02 13:36:33 -08:00
Phil Constantinou
e352784fed Add Z only if needed. 2025-01-02 12:50:29 -08:00
Kostas Stamatakis
61a0227241
simplify test 2024-12-30 23:15:46 +02:00
Kostas Stamatakis
2190a8e0d1
cleanup and add test for json codec 2024-12-30 23:09:19 +02:00
Kostas Stamatakis
6e9fa42fef
fix #2204 2024-12-30 22:54:42 +02:00
Oleksandr Redko
17cd36818c Update comments in generated code to align with Go standards 2024-12-21 20:21:32 +02:00
Jack Christensen
9d851d7c98 Fix integration benchmarks 2024-12-21 08:22:12 -06:00
Ludovico Russo
5c9b565116 fix: #2146
[![Open Source Saturday](https://img.shields.io/badge/%E2%9D%A4%EF%B8%8F-open%20source%20saturday-F64060.svg)](https://www.meetup.com/it-IT/Open-Source-Saturday-Milano/)

Co-authored-by: Alessio Izzo <alessio.izzo86@gmail.com>
2024-10-19 15:43:56 +02:00
Konstantin Grachev
8723855d95
Implement pgtype.UUID.String() 2024-10-09 14:22:10 +03:00
Jack Christensen
3f84e891de
Merge pull request #2142 from jackc/add-xid8
Add xid8 type
2024-10-08 19:04:07 -05:00
Jack Christensen
123b59a57e Ensure planning encodes and scans cannot infinitely recurse
https://github.com/jackc/pgx/issues/2141
2024-10-05 12:20:50 -05:00
Jack Christensen
32a6b1b200 Skip xid8 test on PG < 13 and CRDB 2024-10-05 10:44:13 -05:00
Jack Christensen
f0783c6fbe Add xid8 type
https://github.com/jackc/pgx/discussions/2137
2024-10-05 10:16:42 -05:00
Shean de Montigny-Desautels
7803ec3661
Fix pgtype.Timestamp json unmarshal
Add the missing 'Z' at the end of the timestamp string, so it can be
parsed as timestamp in the RFC3339 format.
2024-09-23 18:12:32 -04:00
Jack Christensen
e9bd382c51
Merge pull request #2114 from jennifersp/master
add byte length check to uint32
2024-08-26 07:28:47 -05:00
Jack Christensen
603f2337d6
Merge pull request #2113 from mateuszkowalke/master
Add comment for pgtype.Interval struct
2024-08-26 07:28:29 -05:00
jennifersp
73bbced270 add byte length check to uint32 2024-08-23 16:17:07 -07:00
mateuszkowalke
4171f554d4 Add additional info for nullable pgtype types
Additional information warns about using nullable types being
used as parameters to query with Valid set to false.
2024-08-23 15:15:40 +02:00
jennifersp
57fd684068 update struct name 2024-08-22 16:51:42 -07:00
jennifersp
926913ad66 rm bound check 2024-08-21 15:12:36 -07:00
jennifersp
b9f77cb1b3 fix typo 2024-08-21 12:27:23 -07:00
jennifersp
218c15a4eb support text scanner for binary format for uint32 2024-08-21 12:04:54 -07:00
Jack Christensen
5747f37d9c Fix: Scan and encode types with underlying types of arrays
Rather than special case the reported issue with UUID and [16]byte, this
commit allows the system to find the underlying type of any type that is
an array.

fixes https://github.com/jackc/pgx/issues/2107
2024-08-15 18:20:07 -05:00
Jack Christensen
a68e14fe5a Explicitly disclaim support for time with time zone 2024-07-23 17:27:05 -05:00
nickcruess-soda
a8aaa37363 fix(test): skip CockroachDB since it doesn't support XML 2024-07-12 09:56:59 -05:00
nickcruess-soda
37681a4f48 chore: remove unused JSONCodec code, correct typo 2024-07-11 15:18:20 -05:00
nickcruess-soda
c7b9dc0e00 feat: add pgtype.XMLCodec based on pgtype.JSONCodec 2024-07-11 15:17:55 -05:00
Nick Farrell
b770252a3b
Fix bug relating to reuse of types
When `LoadTypes` is being called, it does not include the
namespace-qualified types in its result. While these namespaces are
visible to `LoadTypes` itself, `RegisterTypes` will not recognise this
form of the types, only allowing them to be used if they are on the
schema path, and referred to without their namespace component.
2024-07-07 11:26:19 +10:00
Nick Farrell
47977703e1
Load types using a single SQL query
When loading even a single type into pgx's type map, multiple SQL
queries are performed in series. Over a slow link, this is not ideal.
Worse, if multiple types are being registered, this is repeated multiple
times.

This commit add LoadTypes, which can retrieve type
mapping information for multiple types in a single SQL call, including
recursive fetching of dependent types.
RegisterTypes performs the second stage of this operation.
2024-07-01 15:34:17 +10:00