Skip to content

SelectBuilder.Where() broken #114

Closed
Closed

Description

@hahanein

Version: a6b9300

Where statements aren't being transformed into "WHERE IN (?, ...)" statements if the value of a squirrel.Eq key is of type []uint8.

Correct:

package main

import (
        "fmt"

        "github.com/Masterminds/squirrel"
)

func main() {
        query, args, err := squirrel.Select("*").Where(squirrel.Eq{"test": []uint32{1, 2, 3}}).ToSql()
        if err != nil {
                panic(err)
        }

        fmt.Println(query) // SELECT * WHERE test IN (?,?,?)
        fmt.Println(args) // [1 2 3]
}

Bug:

package main

import (
        "fmt"

        "github.com/Masterminds/squirrel"
)

func main() {
        query, args, err := squirrel.Select("*").Where(squirrel.Eq{"test": []uint8{1, 2, 3}}).ToSql()
        if err != nil {
                panic(err)
        }

        fmt.Println(query) // SELECT * WHERE test = ?
        fmt.Println(args) // [[1 2 3]]
}

Activity

  1. lann commented on Jan 11, 2018

    @lann
    Member

    Squirrel doesn't touch values when driver.IsValue(value) is true. It looks like byte is really just an alias for uint8, and driver.IsValue([]byte{}) is true.

    I don't think this can be fixed backward-compatibly.

  2. hahanein commented on Jan 11, 2018

    @hahanein
    Author

    Thank you! Maybe you should warn about this pitfall in the README and the docs.

  3. lann commented on Jan 11, 2018

    @lann
    Member

    Good idea. Added an FAQ section with this.

  4. sundowndev commented on Jun 30, 2026

    @sundowndev

    Wouldn't it be possible to introduce a squirrel.In{} type ?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions