mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
Fixes a speculation, possibly unsupported by escape analysis evidence.
parent
eef1c373d7
commit
351808d590
@ -136,10 +136,11 @@ Only [`NullByte`](https://pkg.go.dev/database/sql/#NullByte), [`NullBool`](https
|
|||||||
`database/sql`. Implementations of database-specific null types are left
|
`database/sql`. Implementations of database-specific null types are left
|
||||||
to the database driver. User types supporting `NULL` can be created by implementing interfaces [`database/sql/driver.Valuer`](https://pkg.go.dev/database/sql/driver/#Valuer) and [`database/sql.Scanner`](https://pkg.go.dev/database/sql/#Scanner).
|
to the database driver. User types supporting `NULL` can be created by implementing interfaces [`database/sql/driver.Valuer`](https://pkg.go.dev/database/sql/driver/#Valuer) and [`database/sql.Scanner`](https://pkg.go.dev/database/sql/#Scanner).
|
||||||
|
|
||||||
You can also pass pointer types. Be careful for performance issues as it
|
You can also pass pointer types.
|
||||||
requires extra memory allocations.
|
|
||||||
|
|
||||||
```go
|
```go
|
||||||
var name *string
|
var name *string
|
||||||
err := db.QueryRowContext(ctx, "SELECT name FROM names WHERE id = $1", id).Scan(&name)
|
err := db.QueryRowContext(ctx, "SELECT name FROM names WHERE id = $1", id).Scan(&name)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
NOTE: Scanning will result in extra heap allocation, regardless of whether you use a pointer or one of the `Null`-types. From the point of pure memory allocation, the two alternatives are analogous and differ only in their intended reader semantic.
|
Loading…
x
Reference in New Issue
Block a user