summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorJustin Bronn <jbronn@gmail.com>2010-02-23 05:22:12 +0000
committerJustin Bronn <jbronn@gmail.com>2010-02-23 05:22:12 +0000
commitc4699b0b8a8503e552de1fe4f873685f7037b337 (patch)
tree63065345b6d2c3f170cbbdf5f9451f0cc2ede1db /docs
parent349827996b5bcf29886bd1e57bc07147d840229e (diff)
Fixed #12806 -- Added an implementation of `RawQuerySet.__getitem__`. Thanks, Bruno ReniƩ.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12504 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
-rw-r--r--docs/topics/db/sql.txt14
1 files changed, 14 insertions, 0 deletions
diff --git a/docs/topics/db/sql.txt b/docs/topics/db/sql.txt
index 075b9b27a3..1433fa52a1 100644
--- a/docs/topics/db/sql.txt
+++ b/docs/topics/db/sql.txt
@@ -91,6 +91,20 @@ query could also be written::
>>> name_map = {'first': 'first_name', 'last': 'last_name', 'bd': 'birth_date', 'pk': 'id'}
>>> Person.objects.raw('SELECT * FROM some_other_table', translations=name_map)
+Index lookups
+-------------
+
+``raw()`` supports indexing, so if you need only the first result you can
+write::
+
+ >>> first_person = Person.objects.raw('SELECT * from myapp_person')[0]
+
+However, the indexing and slicing are not performed at the database level. If
+you have a big amount of ``Person`` objects in your database, it would be more
+efficient to limit the query at the SQL level::
+
+ >>> first_person = Person.objects.raw('SELECT * from myapp_person LIMIT 1')[0]
+
Deferring model fields
----------------------