Skip to content

feat: multi-column (tuple) expansion in In#998

Open
sonnemusk wants to merge 1 commit into
jmoiron:masterfrom
sonnemusk:feat/multi-col-in
Open

feat: multi-column (tuple) expansion in In#998
sonnemusk wants to merge 1 commit into
jmoiron:masterfrom
sonnemusk:feat/multi-col-in

Conversation

@sonnemusk

Copy link
Copy Markdown

Summary

sqlx.In now expands slice-of-slices / slice-of-arrays as SQL tuples for multi-column IN lists (issue #294).

q, args, err := sqlx.In(
    `SELECT * FROM t WHERE (id, typ) IN (?)`,
    [][]interface{}{{1, "a"}, {2, "b"}},
)
// q:    SELECT * FROM t WHERE (id, typ) IN ((?, ?), (?, ?))
// args: []interface{}{1, "a", 2, "b"}

Also works with fixed-size rows:

sqlx.In(`WHERE (a, b) IN (?)`, [][2]int{{1, 2}, {3, 4}})

Rules

  • Element type must be slice or array (not []byte — still a single bind value)
  • All rows must share the same width
  • Empty outer slice / empty tuple still errors as before

Fixes #294

When a bind argument is a slice of slices/arrays (other than []byte),
In expands it as SQL tuples for multi-column IN lists:

  In("SELECT * FROM t WHERE (id, typ) IN (?)",
     [][]interface{}{{1, "a"}, {2, "b"}})
  // -> WHERE (id, typ) IN ((?, ?), (?, ?))

Addresses jmoiron#294.
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

Successfully merging this pull request may close these issues.

Multiple Columns using sqlx.In

1 participant