Commit Graph

14 Commits (2a653b4a8d2cddc7164f079ae1eff3b6ff616a55)

Author SHA1 Message Date
Cemre Mengu 2a653b4a8d fix: handle null interface for json
When using `scany` I encountered the following case. This seems to fix it.

Looks like null `jsonb` columns cause the problem. If you create a table like below you can see that the following code fails. Is this expected?

```sql
CREATE TABLE test (
	a int4 NULL,
	b int4 NULL,
	c jsonb NULL
);

INSERT INTO test (a, b, c) VALUES (1, null, null);
```

```go
package main

import (
	"context"
	"log"

	"github.com/georgysavva/scany/v2/pgxscan"
	"github.com/jackc/pgx/v5"
)

func main() {
	var rows []map[string]interface{}
	conn, _ := pgx.Connect(context.Background(), , ts.PGURL().String())
	
	// this will fail with can't scan into dest[0]: cannot scan NULL into *interface {}
	err := pgxscan.Select(context.Background(), conn, &rows, `SELECT c from test`) 
	
	// this works
	// err = pgxscan.Select(context.Background(), conn, &rows, `SELECT a,b from test`)
	
	if err != nil {
		panic(err)
	}

	log.Printf("%+v", rows)
}
```
2023-03-25 10:22:11 -05:00
Jack Christensen e48e7a7189 Fix scanning json column into **string
refs https://github.com/jackc/pgx/issues/1470
2023-01-20 18:38:11 -06:00
Jack Christensen e66ad1bcec Fix encode to json ignoring driver.Valuer
https://github.com/jackc/pgx/issues/1430
2022-12-23 13:44:09 -06:00
Jack Christensen 279c3c0a20 Fix: json values work with sql.Scanner
https://github.com/jackc/pgx/issues/1418
2022-12-06 19:44:55 -06: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 f14fb3d692 Replace interface{} with any 2022-04-09 09:12:55 -05:00
Jack Christensen e5685a34fc Simplify encoding extended query arguments 2022-03-05 20:16:57 -06:00
Jack Christensen 9c538cd4a9 Remove actualTarget argument 2022-02-21 09:30:01 -06:00
Jack Christensen 1f2f239d09 Renamed pgtype.ConnInfo to pgtype.Map 2022-02-21 09:13:09 -06:00
Jack Christensen 5ed95dcd1c Expose wrap functions on ConnInfo
- Remove rarely used ScanPlan.Scan arguments
- Plus other refactorings and fixes that fell out of this change.
- Plus rows Scan now handles checking for changed type.
2022-01-22 17:50:19 -06:00
Jack Christensen 8b27725f5b Convert json and jsonb to Codec 2022-01-18 16:04:25 -06:00
Jack Christensen 44214b7854 Import to pgx main repo in pgtype subdir 2021-12-04 13:07:54 -06:00