Commit 12eb6ae
committed
Fix: json/jsonb sql.Scanner source type is []byte
Previously, when scanning a json/jsonb value into a sql.Scanner via
database/sql the source value was a []byte. However, when scanning into
a sql.Scanner via pgx the source value was a string. This change ensures
that the source value is consistently a []byte.
The problem was pgx has one scan plan for sql.Scanner when a Codec is
available and another when it is not. When a Codec is not available,
this means we don't know the underlying type, so all we can do is pass
text formatted values as a string and binary formatted values as a
[]byte. However, when a Codec is available we can use the Codec to
call DecodeDatabaseSQLValue which provides the proper source type.
JSONCodec.planScan was incorrectly using scanPlanSQLScanner instead of
scanPlanCodecSQLScanner, which resulted in the source type being a
string.1 parent 79b1775 commit 12eb6ae
2 files changed
Lines changed: 23 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
160 | | - | |
| 160 | + | |
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
360 | 360 | | |
361 | 361 | | |
362 | 362 | | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
0 commit comments