Skip to content

sql.NullX used incorrectly in postgres queries #438

Open
@Gilthans

Description

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:

  • postgres
  • mysql
  • sqlite3

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions