> Why do you want to use raw SQL? What's wrong with using the normal
> Django ORM?
One reason that I use in my own code is to snapshot multiple
values efficiently, a'la:
INSERT INTO stored_groups
(statementitem_id, groupname, groupvalue)
SELECT si.id, g.groupname, gv.groupvalue
FROM statementitem si
INNER JOIN active_profile ap
ON si.profileid = ap.id
INNER JOIN profile_groups pg
ON pg.profileid = ap.id
INNER JOIN groupvalues gv
ON pg.groupvalueid = gv.id
INNER JOIN groupnames gn
ON gn.id = gv.groupnameid
WHERE ...
This[*] takes a snapshot of the current/active group name/value
pairs associated with a particular statementitem, at the time it
appeared on the statement, and dumps the results into the
stored_groups table. This can trigger N*M insertions (N = number
of statementitems to process, M = avg # of group-values per
statementitem), all done efficiently on the server with one
query. Via the ORM, this takes N*M round-trips to the server (or
at least one humongous round-trip with N*M INSERTs within); via
the raw SQL, it's one efficient round-trip to the server.
Granted, it's a highly tuned edge-case, but
1) it creates HUGE savings in DB-communication overhead, and
2) Django already allows for it via the connection object
-tim
[*] I'm pulling SQL this off the top of my head, as I'm away from
the actual code-base currently, but it should be pretty similar
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---