mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
Revert
parent
351808d590
commit
507dc0f3e9
@ -136,11 +136,9 @@ 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.
|
You can also pass pointer types. Be careful for performance issues as it 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