goqu icon indicating copy to clipboard operation
goqu copied to clipboard

`sql.NullX` used incorrectly in postgres queries

Open Gilthans opened this issue 1 year ago • 1 comments

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

Gilthans avatar Jan 08 '25 11:01 Gilthans

Following the thread

nitaysol avatar Jan 23 '25 10:01 nitaysol