tags:

views:

82

answers:

2

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?

+1  A: 

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

Manu
+8  A: 

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).

PiotrLegnica