orokusaki
orokusaki

Reputation: 57198

Django ORM: Why would Django use SELECT (1) on its own?

When using Django (with SQLite3) I noticed the following query in connection.queries :

"sql": "SELECT (1) AS \"a\" FROM \"blog_comment\" WHERE \"blog_comment\".\"id\" = 5  LIMIT 1"

I understand what the query does (just returns the first column from each matching row), but why do this?

Is it just an inexpensive way of checking for EXISTS in SQLite3? If so, in what context would it be used on its own?

Upvotes: 5

Views: 1551

Answers (1)

gbn
gbn

Reputation: 432667

It is just checking for existence of rows.
It doesn't have any meaning otherwise because "1" is a constant value

Upvotes: 9

Related Questions