fallhunter
fallhunter

Reputation: 551

the sql generated in django

when i print the sql generated in connection.queries:

i found some sql like this:

SELECT (1) AS `a` FROM `auth_user` WHERE `auth_user`.`id` = 2 

what's that mean?

Upvotes: 2

Views: 235

Answers (2)

Cat Plus Plus
Cat Plus Plus

Reputation: 129764

It's used to check if that row exists, without actually fetching any data (constructed by django.db.models.sql.query.BaseQuery.has_results, called by e.g. QuerySet.exists).

Upvotes: 12

Manu
Manu

Reputation: 29143

Selects value '1' under the alias (column name) 'a' for each entry of table (or view) 'auth_user' if condition auth_user.id=2 holds.

In other words: it returns a single field ('a') with the value '1' for all users with id=2

Upvotes: 1

Related Questions