sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
11.54k stars 741 forks source link

SQLite cannot use an empty slice for `NOT IN` #3451

Open Evan-Prophet opened 1 week ago

Evan-Prophet commented 1 week ago

Version

1.26.0

What happened?

When using NOT IN & SQLite, if you pass it an empty slice, it will never match. This is because of:

query = strings.Replace(query, "/*SLICE:userIDs*/?", "NULL", 1)

The replacement to NULL will never be true.

E.g.:

# No Results
select "example" as example WHERE example NOT IN (NULL);

# Results
select "example" as example WHERE example NOT IN ();

Relevant log output

No response

Database schema

No response

SQL queries

No response

Configuration

No response

Playground URL

https://play.sqlc.dev/p/1e688f1a8a0033e2e2bbbc3c0621e541cd11ef25a8ccd20aedcdd36d918892fa

What operating system are you using?

macOS

What database engines are you using?

SQLite

What type of code are you generating?

Go