Skip to content

Incorrect SQL query when nil Or clause #382

@MartyHub

Description

@MartyHub

Hello,

not sure if this is expected?

https://go.dev/play/p/yMEuRKDSOSI

package main

import (
	"fmt"

	sq "github.com/Masterminds/squirrel"
)

func getFilter() sq.Or {
	return nil
}

func main() {
	users := sq.Select("*").From("users").Where(getFilter())

	sql, _, err := users.ToSql()
	if err != nil {
		panic(err)
	}

	fmt.Println(sql)
}

=> SELECT * FROM users WHERE (1=0)

IMHO this is really tricky and error-prone

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions