mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
Update information about NULL handling
parent
92927b5d0b
commit
1a22b4bb41
@ -114,7 +114,7 @@ If a database column is nullable, one of the types supporting null values should
|
|||||||
For example, if the name column in the names table is nullable:
|
For example, if the name column in the names table is nullable:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
var name NullString
|
var name sql.NullString
|
||||||
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)
|
||||||
...
|
...
|
||||||
if name.Valid {
|
if name.Valid {
|
||||||
@ -124,6 +124,6 @@ if name.Valid {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Only NullBool, NullFloat64, NullInt64 and NullString are implemented in
|
Only [`NullBool`](https://golang.org/pkg/database/sql/#NullBool), [`NullFloat64`](https://golang.org/pkg/database/sql/#NullFloat64), [`NullInt64`](https://golang.org/pkg/database/sql/#NullInt64), [`NullInt32`](https://golang.org/pkg/database/sql/#NullInt32), [`NullString`](https://golang.org/pkg/database/sql/#NullString) and [`NullTime`](https://golang.org/pkg/database/sql/#NullTime) are implemented in
|
||||||
database/sql. Implementations of database-specific null types are left
|
`database/sql`. Implementations of database-specific null types are left
|
||||||
to the database driver.
|
to the database driver. User types supporting `NULL` can be created by implementing interfaces [`database/sql/driver.Valuer`](https://golang.org/pkg/database/sql/driver/#Valuer) and [`database/sql.Scanner`](https://golang.org/pkg/database/sql/#Scanner).
|
Loading…
x
Reference in New Issue
Block a user