goqu
goqu copied to clipboard
`sql.NullX` used incorrectly in postgres queries
Describe the bug
When using a null sql.NullInt32 in a query using postgres dialect, the created query uses WHERE x = NULL, instead of the correct WHERE x is NULL.
To Reproduce
package main
import (
"database/sql"
"fmt"
"github.com/doug-martin/goqu/v9"
)
func main() {
sql, _, _ := goqu.Dialect("postgres").From(goqu.T("table")).Select("Id").Where(goqu.Ex{"Val": sql.NullInt32{}}).ToSQL()
fmt.Println(sql)
sql, _, _ = goqu.Dialect("postgres").From(goqu.T("table")).Select("Id").Where(goqu.Ex{"Val": nil}).ToSQL()
fmt.Println(sql)
}
=> SELECT "Id" FROM "table" WHERE ("Val" = NULL) // Wrong SELECT "Id" FROM "table" WHERE ("Val" IS NULL) // Right
Expected behavior
When using sql.NullX as a null value, expect to use correctly
Dialect:
- [x] postgres
- [ ] mysql
- [ ] sqlite3
Following the thread