Using standard database/sql Row.Scan()
I have a problem with null values in the row. Without considering possible null values in a row, I can get scan errors like <nil> -> *string
. This is quite common using LEFT JOIN queries or weak defined tables missing NO NULL column constraints.
There are sql.NullXXX
types (e.g. sql.NullInt64) which can be used to scan possible null value from a row, and then check if the value is .Valid
. However, these types don’t implement JSON marshalling, and those more logic and coding is required.
To solve this, is it better approach to COALESCE()
column values in SQL query or do some extra coding in golang code?