Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

the sql generated in django

Tags:

sql

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?

like image 385
fallhunter Avatar asked Apr 13 '26 03:04

fallhunter


1 Answers

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

like image 106
Cat Plus Plus Avatar answered Apr 14 '26 17:04

Cat Plus Plus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!