441 Commits

Author SHA1 Message Date
Jack Christensen
a581124dea Encode with driver.Valuer after trying TryWrapEncodePlanFuncs
However, all builtin TryWrapEncodePlanFuncs check for driver.Valuer and
skip themselves if it is found.
2022-10-12 19:52:57 -05:00
Jack Christensen
c4407fb36e Prevent infinite loop for driver.Valuer / Codec edge case
A `driver.Valuer()` results in a `string` that the `Codec` for the
PostgreSQL type doesn't know how to handle. That string is scanned into
whatever the default type for that `Codec` is. That new value is
encoded. If the new value is the same type as the original type than an
infinite loop occured. Check that the types are different.

https://github.com/jackc/pgx/issues/1331
2022-10-12 19:46:15 -05:00
Jack Christensen
af0b896290 Allow scanning null even if PG and Go types are incompatible
refs https://github.com/jackc/pgx/issues/1326
2022-10-08 09:10:43 -05:00
Jack Christensen
5655f9d593 Fix scan to pointer to pointer to renamed type
refs https://github.com/jackc/pgx/issues/1326
2022-10-08 08:10:40 -05:00
Jack Christensen
222e3b37bc Prefer driver.Value over wrap plans when encoding
This is tricky due to driver.Valuer returning any. For example, we can
plan for fmt.Stringer because it always returns a string.

Because of this driver.Valuer was always handled as the last option. But
with pgx v5 now having the ability to find underlying types like a
string and supporting fmt.Stringer it meant that driver.Valuer was
often not getting called because something else was found first.

This change tries driver.Valuer immediately after the initial PlanScan
for the Codec. So a type that directly implements a pgx interface should
be used, but driver.Valuer will be prefered before all the attempts to
handle renamed types, pointer deferencing, etc.

fixes https://github.com/jackc/pgx/issues/1319
fixes https://github.com/jackc/pgx/issues/1311
2022-10-01 12:20:23 -05:00
Jack Christensen
89f69aaea9 Date text encoding includes leading zero for month and day
e.g. 2000-01-01 instead of 2000-1-1. PostgreSQL accepted it without
zeroes but our text decoder didn't. This caused a problem when we needed
to take a value and encode to text so something else could parse it as
if it had come from the PostgreSQL server in text format. e.g.
database/sql compatibility.
2022-10-01 10:41:40 -05:00
Jack Christensen
335c8621ff Fix sqlScannerWrapper NULL handling
https://github.com/jackc/pgx/issues/1312
2022-09-24 10:30:12 -05:00
Jack Christensen
ac9d4f4d96 Encode text for Lseg includes [ and ]
https://github.com/jackc/pgtype/issues/187
2022-09-24 10:30:12 -05:00
yogipristiawan
72e4b88e56 feat: add marshalJSON for float8 type 2022-09-24 10:00:40 -05:00
Jack Christensen
f8d088cfb6 Fix JSON scan not completely overwriting destination
See https://github.com/jackc/pgtype/pull/185 for original report in
pgx v4 / pgtype.
2022-09-02 18:37:02 -05:00
Jack Christensen
fe3a4f3150 Standardize casing for NULL in error messages 2022-08-22 21:01:18 -05:00
Jack Christensen
2e73d1e8ee Improve error message when failing to scan a NULL::json 2022-08-22 20:56:36 -05:00
Jack Christensen
0d5d8e0137 Fallback to other format when encoding query arguments
The preferred format may not be possible for certain arguments. For
example, the preferred format for numeric is binary. But if
shopspring/decimal is being used without jackc/pgx-shopspring-decimal
then it will use the database/sql/driver.Valuer interface. This will
return a string. That string should be sent in the text format.

A similar case occurs when encoding a []string into a non-text
PostgreSQL array such as uuid[].
2022-08-22 20:26:38 -05:00
Jack Christensen
02d9a5acd8 Fix naming of some tests 2022-08-13 08:41:06 -05:00
Jack Christensen
8256ab147f Add build tag to skip default PG type registration
https://github.com/jackc/pgx/issues/1273#issuecomment-1207338136
2022-08-13 08:09:44 -05:00
Jack Christensen
c3258b7f52 Fix scan pointer to pointer to nil slice
https://github.com/jackc/pgx/issues/1263
2022-07-30 09:10:50 -05:00
Jack Christensen
2da0a11c52 Skip some examples on CockroachDB 2022-07-23 10:52:35 -05:00
Jack Christensen
ce378b4d9c Skip example on Cockroach DB 2022-07-23 10:21:01 -05:00
Jack Christensen
5cee04a026 Add child records docs and examples 2022-07-23 10:11:13 -05:00
Jack Christensen
3595561d9a More doc improvements 2022-07-23 09:29:25 -05:00
Jack Christensen
759e47dba3 Merge branch 'master' into v5-dev 2022-07-12 07:26:00 -05:00
Jack Christensen
d5807f01ed Restore test from v4 2022-07-12 06:57:56 -05:00
Jack Christensen
224393188d Fix InetCodec.DecodeValue 2022-07-11 08:07:23 -05:00
Jack Christensen
e7eb8a3250 Use netip package for representing inet and cidr types 2022-07-10 14:31:55 -05:00
Jack Christensen
7974a102fc Improve Scan error messages 2022-07-09 21:47:39 -05:00
Jack Christensen
b662ab6767 Better encode error message 2022-07-09 21:40:44 -05:00
Jack Christensen
90c2dc6f68 Rename ForEachScannedRow to ForEachRow 2022-07-09 16:47:28 -05:00
Jack Christensen
76946fb5a3 Replace QueryFunc with ForEachScannedRow 2022-07-07 20:29:04 -05:00
Jack Christensen
82ca09e645 Numeric infinity only supported on PG 14+
Move to PG 14+ specific test
2022-06-25 13:33:09 -05:00
Jack Christensen
c0a4d1b9ce Add a few tests 2022-06-20 20:43:56 -05:00
Jack Christensen
989a4835de Remove rune to text conversion
Because rune is an alias for int32 this caused some very surprising
results. e.g. inserting int32(65) into text would insert "A" instead of
"65".
2022-05-12 17:13:49 -05:00
Jack Christensen
01190e5d78 Update ScanPlan.Scan documentation 2022-04-30 08:29:51 -05:00
Jack Christensen
0c6266ef30 Fix scanning null did not overwrite slice 2022-04-26 14:52:01 -05:00
Jack Christensen
7427820aba Scan binary UUID to string
https://github.com/jackc/pgx/issues/1191
2022-04-26 08:37:10 -05:00
Jack Christensen
f9857b73d9 Skip multirange tests on PG < 14 2022-04-23 16:55:24 -05:00
Jack Christensen
dfb681d716 Build / rewrite / port multirange support 2022-04-23 12:50:18 -05:00
Jack Christensen
126b582f19 Make range helpers private 2022-04-23 11:10:04 -05:00
Jack Christensen
cb45e85954 Merge remote-tracking branch 'pgtype/master' into v5-dev 2022-04-23 11:00:07 -05:00
Jack Christensen
468b793282 Skip tests with unsupported types on CockroachDB 2022-04-23 10:34:53 -05:00
Jack Christensen
cc7de81d3b Make array helpers private 2022-04-16 14:21:40 -05:00
Jack Christensen
a01a9ee6df Automatically register Array and FlatArray 2022-04-16 14:04:25 -05:00
Jack Christensen
fccaebc93d Add pgtype.Map.SQLScanner
This enables compatibility with database/sql for types that cannot
implement Scan themselves.
2022-04-16 13:38:27 -05:00
Jack Christensen
f1a4ae3070 Add Array and FlatArray container types 2022-04-16 11:33:45 -05:00
Jack Christensen
d4abe83edb Revert use generics for RangeCodec
Reverted almost all of 976b1e0.

Still may consider a way to get DecodeValue to be strongly typed but
that feature isn't worth the complications of generics. Especially in
that applying this style to ArrayCodec would make Conn.LoadType
impossible for arrays.
2022-04-16 10:39:12 -05:00
Jack Christensen
976b1e03a9 Use generics for RangeCodec
This allows DecodeValue to return a more strongly typed value.
2022-04-09 10:21:17 -05:00
Jack Christensen
c8025fd79a Use generics for Range values 2022-04-09 09:34:37 -05:00
Jack Christensen
f14fb3d692 Replace interface{} with any 2022-04-09 09:12:55 -05:00
Jack Christensen
829babcea9 Better number to string handling
Avoid ambiguity of stringWrapper implementing Int64Scanner and
Float64Scanner.
2022-04-09 09:09:46 -05:00
Jack Christensen
8cf6721d66 Better int64 / numeric compat and text fixes 2022-04-02 16:55:05 -05:00
Jack Christensen
53ec52aa17 Fix out of date pgtype/int_test.go.erb 2022-04-02 14:41:33 -05:00