Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql.NullX used incorrectly in postgres queries #438

Open
1 of 3 tasks
Gilthans opened this issue Jan 8, 2025 · 0 comments
Open
1 of 3 tasks

sql.NullX used incorrectly in postgres queries #438

Gilthans opened this issue Jan 8, 2025 · 0 comments

Comments

@Gilthans
Copy link

Gilthans commented Jan 8, 2025

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant