B
B
beduin012018-02-19 11:38:12
SQL
beduin01, 2018-02-19 11:38:12

Is there a difference between = and IN ( ... )?

There is a snippet in the code:

if id is not None:
            if type(id) is list:
                q = q.filter(Model.id.in_(id))
            else:
                q = q.filter(Model.id == id)

I'm wondering if the second condition is necessary? Maybe you can get a selection simply through: Just if there is one value in brackets, then it will work just like:
SELECT * FROM TableName WHERE ID IN ( ... )
SELECT * FROM TableName WHERE ID IN (42)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav, 2018-03-01
@beduin01

There was a similar question on stackoverflow. They concluded that there was no difference.
The query EXPLAIN is the same in both cases
https://stackoverflow.com/questions/9926433/mysql-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question