goqu icon indicating copy to clipboard operation
goqu copied to clipboard

Select statement has invalid NULL check syntax when using implicit nil value

Open sieuwerts opened this issue 3 years ago • 1 comments

Describe the bug Select statement has invalid NULL check syntax when using goqu.Ex as where statement with implicit nil value (nil pointer).

To Reproduce https://play.golang.org/p/X9YaafCJmn-

package main

import (
	"fmt"

	"github.com/doug-martin/goqu/v9"
	_ "github.com/doug-martin/goqu/v9/dialect/postgres"
)

func main() {
	db := goqu.Dialect("postgres")
	var val *int

	query, _, _ := db.From(goqu.T("table")).Where(goqu.Ex{"explicit_nil": nil, "implicit_nil": val}).ToSQL()

	fmt.Println(query) // SELECT * FROM "table" WHERE (("explicit_nil" IS NULL) AND ("implicit_nil" = NULL))
}

Expected behaviour When using goqu.Ex in a while condition, I expect to get ...WHERE ("field" IS NULL)... and not ...WHERE ("field" = NULL)..., regardless if I use an implicit, or explicit nil value.

Dialect:

  • [x] postgres
  • [ ] mysql
  • [ ] sqlite3

sieuwerts avatar May 10 '21 08:05 sieuwerts

I just hit this, is there any update or workaround?

nitaigao avatar Apr 25 '22 12:04 nitaigao