Skip to content

"IN" on empty array causes invalid SQL #709

Closed
@eran-pinhas

Description

@eran-pinhas

Not sure if it's by design or a bug but...

Trying to run db.selectFrom('person').selectAll().where('id', 'in', []) causes an invalid SQL (see image below👇 the () part is invalid).

Now obviously, this query doesn't make a lot of sense, and you can simply assume there would be 0 rows returned, but IMO ot. makes sense when in the TypeScript context, and also SQL generating library that creates an invalid SQL is a bit weird. The ways I think we can overcome this "issue" really depends on the philosophy Kysely is based on:

  • Leave it as is (Although I would suggest updating the docs to explain this non-trivial case)
  • Throwing a runtime error
  • replacing it with some sort of false statement (like IN (null) which should be equivalent)

Let me know what you guys think...

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiRelated to library's APIduplicateThis issue or pull request already existsenhancementNew feature or requestgreenlitReady for implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions