3695 Commits

Author SHA1 Message Date
Jack Christensen
d0475cab1b Skip multirange tests on PG < 14 2024-05-19 16:54:44 -05:00
Jack Christensen
b4f61c94a8 Skip nested array test on CockroachDB 2024-05-19 08:20:28 -05:00
Jack Christensen
9316da55e5 Add Scan and Value to pgtype.Multirange[T] 2024-05-19 08:11:05 -05:00
Jack Christensen
a07f17579d Add Scan and Value to pgtype.Range[T] 2024-05-19 08:03:34 -05:00
Jack Christensen
06d85e064d Add Scan and Value methods to FlatArray and Array
Support direct usage in database/sql.

https://github.com/jackc/pgx/issues/1458
https://github.com/jackc/pgx/issues/1779
https://github.com/jackc/pgx/issues/1956
https://github.com/jackc/pgx/issues/1662
2024-05-19 07:56:16 -05:00
Mitar
732889728f Add support for custom JSON marshal and unmarshal.
The Codec interface is now implemented by *pgtype.JSONCodec
and *pgtype.JSONBCodec instead of pgtype.JSONCodec and
pgtype.JSONBCodec, respectively. This is technically a breaking
change, but it is extremely unlikely that anyone is depending on this,
and if there is downstream breakage it is trivial to fix.

Fixes #2005.
2024-05-18 08:02:09 -05:00
Mitar
e1b90cf620 Add ltree extension requirement. 2024-05-18 07:56:47 -05:00
Jack Christensen
ded01c0cd9 Fix TestParseConfigEnvLibpq unsetting envars
This would cause tests to fail if PG* variables were used for the
default connection config for other tests.

Previously broken by 0080acf318d162a1128928bc32eadf45cef61fd2.
2024-05-17 09:19:36 -05:00
ngavinsir
532bf8f583 adjust test 2024-05-14 20:28:02 -05:00
ngavinsir
169067a364 remove ctx from release tracer 2024-05-14 20:28:02 -05:00
ngavinsir
659525c961 trace release 2024-05-14 20:28:02 -05:00
ngavinsir
4dd1810d8b persist ctx in pgxpool conn 2024-05-14 20:28:02 -05:00
ngavinsir
25914e21f3 add release tracer 2024-05-14 20:28:02 -05:00
ngavinsir
19fcb54564 add pool to trace acquire 2024-05-14 20:28:02 -05:00
ngavinsir
a39632db43 feat: pgx pool acquire tracer 2024-05-14 20:28:02 -05:00
Oleksandr Redko
c05cce7d41 Fix test asserts: reverse expected-actual 2024-05-14 20:07:10 -05:00
Oleksandr Redko
0080acf318 Simplify config tests by using T.Setenv, T.TempDir 2024-05-14 20:06:18 -05:00
Mitar
c81bba8690 Use pgtype.PreallocBytes in LargeObject's Read.
Fixes #1876.
2024-05-14 07:03:24 -05:00
Pavlo Golub
523411a3fb make QueuedQuery.Fn property public, closes #1878
This commit fixes the overlook of the #1886 where SQL and Arguments
properties were exposed
2024-05-12 09:03:47 -05:00
Jack Christensen
a966716860 Replace DSN with keyword/value in comments and documentation
The term DSN is not used in the PostgreSQL documentation. I'm not sure
why it was originally used. Use the correct PostgreSQL terminology.
2024-05-11 14:33:35 -05:00
Jack Christensen
cf50c60869 Fix error check on CI 2024-05-11 14:33:13 -05:00
Jack Christensen
8db971660e Failed connection attempts include all errors
A single Connect("connstring") may actually make multiple connection
requests due to TLS or HA configuration. Previously, when all attempts
failed only the last error was returned. This could be confusing.
Now details of all failed attempts are included.

For example, the following connection string:

host=localhost,127.0.0.1,foo.invalid port=1,2,3

Will now return an error like the following:

failed to connect to `user=postgres database=pgx_test`:
	lookup foo.invalid: no such host
	[::1]:1 (localhost): dial error: dial tcp [::1]:1: connect: connection refused
	127.0.0.1:1 (localhost): dial error: dial tcp 127.0.0.1:1: connect: connection refused
	127.0.0.1:2 (127.0.0.1): dial error: dial tcp 127.0.0.1:2: connect: connection refused

https://github.com/jackc/pgx/issues/1929
2024-05-11 14:25:03 -05:00
Jack Christensen
48cdd7bab0 Allow scanning time without time zone into string
https://github.com/jackc/pgx/issues/2002
2024-05-10 10:52:41 -05:00
Jack Christensen
579a320c1c pgconn.SafeToRetry checks for wrapped errors
Use errors.As instead of type assertion.

Port 4e2e7a040579c1999c0766642d836eb28c6e2018 to v5

Credit to tjasko
2024-05-09 17:59:16 -05:00
Carlos Pérez-Aradros Herce
01d649b2bf Do not encode interval microseconds when they are 0
This make the encode match what postgres does
2024-05-09 17:29:13 -05:00
Jack Christensen
48ae1f4b2c Fix ResultReader.Read() to handle nil values
The ResultReader.Read() method was erroneously converting nil values
to []byte{}.

https://github.com/jackc/pgx/issues/1987
2024-05-09 17:13:26 -05:00
WGH
e4f72071f8 Document that generic helpers call rows.Close()
Existing generic helpers always call defer rows.Close().
Examples of their usage also omit external defer rows.Close() call.

For clarity, state that explicitly, because that's another point
why one would want to switch to generic helpers from manually written
rows.Next() loop.
2024-05-09 15:54:48 -05:00
Jack Christensen
6f0deff015 Add custom data to pgconn.PgConn
https://github.com/jackc/pgx/issues/1896
2024-05-09 15:39:28 -05:00
Jack Christensen
8649231bb3 Add ScanLocation to pgtype.TimestampCodec
If ScanLocation is set, the timestamps will be assumed to be in the
given location when scanning from the database.

The Codec interface is now implemented by *pgtype.TimestampCodec instead
of pgtype.TimestampCodec. This is technically a breaking change, but it
is extremely unlikely that anyone is depending on this, and if there is
downstream breakage it is trivial to fix.

https://github.com/jackc/pgx/issues/1195
https://github.com/jackc/pgx/issues/1945
2024-05-08 08:35:05 -05:00
Jack Christensen
33360ab479 Add ScanLocation to pgtype.TimestamptzCodec
If ScanLocation is set, it will be used to convert the time to the given
location when scanning from the database.

The Codec interface is now implemented by *pgtype.TimestamptzCodec
instead of pgtype.TimestamptzCodec. This is technically a breaking
change, but it is extremely unlikely that anyone is depending on this,
and if there is downstream breakage it is trivial to fix.

https://github.com/jackc/pgx/issues/1195
https://github.com/jackc/pgx/issues/1945
2024-05-08 08:35:05 -05:00
Jack Christensen
c31619d08b Improve docs for customizing context cancellation 2024-05-08 08:08:21 -05:00
Jack Christensen
ec9bb2ace7 Improve flickering test on CI 2024-05-08 07:54:17 -05:00
Jack Christensen
93a579754b Add CancelRequestContextWatcherHandler
This allows a context to cancel a query by sending a cancel request to
the server before falling back to setting a deadline.
2024-05-08 07:41:02 -05:00
Jack Christensen
42c9e9070a Allow customizing context canceled behavior for pgconn
This feature made the ctxwatch package public.
2024-05-08 07:41:02 -05:00
Oleksandr Redko
60a01d044a Fix typos in doc comments 2024-04-17 12:00:02 -05:00
Zach Olstein
8f69e45a53 fixup! Cache reflection analysis in RowToStructBy... 2024-04-16 13:08:16 -05:00
Zach Olstein
ec98406207 Cache reflection analysis in RowToStructBy...
Modify the RowToStructByPos/Name functions to store the computed mapping
of columns to struct field locations in a cache to reuse between calls.
Because this computation can be expensive and the same few results will
frequently be reused, caching these results provides a significant
speedup.

For positional mappings, we can key the cache by just the struct-type.
However, for named mappings, the key must include a representation of
the columns, in order, since different columns produce different
mappings.
2024-04-16 13:08:16 -05:00
Jack Christensen
8db0f280fb Add benchmarks for RowToStructBy(Pos|Name) 2024-04-16 12:59:40 -05:00
Felix Röhrich
fc416d237a make parsing stricter and add corresponding test 2024-04-16 12:18:06 -05:00
Jack Christensen
a3d9120636 Add SeverityUnlocalized field to PgError / Notice
https://github.com/jackc/pgx/issues/1971
2024-04-07 08:58:10 -05:00
Carlos Pérez-Aradros Herce
78b22c3d2f fix tests 2024-03-20 18:21:11 -05:00
Carlos Pérez-Aradros Herce
221ad1b84c Add support for macaddr8 type
Postgres also has a `macaddr8` type, this PR adds support for it, using
the same codec as `macaddr`
2024-03-20 18:21:11 -05:00
Tomas Zahradnicek
b6e5548341 StrictNamedArgs 2024-03-16 10:59:31 -05:00
Jack Christensen
1b6227af11 Remove verbose flag from go test command on CI
It is more often that interesting information is buried by the verbose
output than the verbose output is useful. It can be reenabled later if
necessary.
2024-03-16 09:52:50 -05:00
Jack Christensen
c1fce377ee Test Go 1.22 and drop Go 1.20 from testing on CI 2024-03-16 09:44:23 -05:00
Jack Christensen
7fd6f2a4f5 Disable parallel testing on Github Actions CI
Tests were failing with:
Error: Process completed with exit code 143.

This appears to mean that Github Actions killed the runner.

See https://github.com/jackc/pgx/actions/runs/8216337993/job/22470808811
for an example.

It appears Github Actions kills runners based on resource usage. Running
tests one at a time reduces the resource usage and avoids the problem.

Or at least that's what I presume is happening. It sure is fun debugging
issues on cloud systems where you have limited visibility... :(

fixes https://github.com/jackc/pgx/issues/1934
2024-03-16 09:41:51 -05:00
Jack Christensen
78a0a2bf41 Fix spelling in changelog v5.5.5 2024-03-09 12:16:20 -06:00
Jack Christensen
a17f064492 Update changelog 2024-03-09 12:12:41 -06:00
Jack Christensen
49b6aad319 Use spaces instead of parentheses for SQL sanitization
This still solves the problem of negative numbers creating a line
comment, but this avoids breaking edge cases such as `set foo to $1`
where the substition is taking place in a location where an arbitrary
expression is not allowed.

https://github.com/jackc/pgx/issues/1928
2024-03-09 12:09:42 -06:00
Felix
0cc4c14e62 Add test to validate CollectRows for empty Rows
https://github.com/jackc/pgx/issues/1924
https://github.com/jackc/pgx/issues/1925
2024-03-06 22:05:32 -06:00