[SQL-CVS] r4305 - SQLObject/trunk/docs
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2010-12-16 09:45:32
|
Author: phd Date: Thu Dec 16 02:45:23 2010 New Revision: 4305 Log: Added a section written by Imri Goldberg. Modified: SQLObject/trunk/docs/SQLBuilder.txt Modified: SQLObject/trunk/docs/SQLBuilder.txt ============================================================================== --- SQLObject/trunk/docs/SQLBuilder.txt Wed Dec 15 20:11:38 2010 (r4304) +++ SQLObject/trunk/docs/SQLBuilder.txt Thu Dec 16 02:45:23 2010 (r4305) @@ -143,3 +143,25 @@ :height: 15 :width: 80 :alt: Get SQLObject at SourceForge.net. Fast, secure and Free Open Source software downloads + +Nested SQL statements (subqueries) +================================== + +There are a few special operators that receive as parameter SQL +statements. These are IN, NOTIN, EXISTS, NOTEXISTS, SOME, ANY and ALL. +Consider the following example: You are interested in removing records +from a table using deleteMany. However, the criterion for doing so +depends on another table. + +You would expect the following to work:: + + >> PersonWorkplace.deleteMany(where= + ((PersonWorkplace.q.WorkplaceID==Workplace.q.id) & + (Workplace.q.id==SOME_ID))) + +But this doesn't work! However, you can't do a join in a deleteMany +call. To work around this issue, use IN:: + + >> PersonWorkplace.deleteMany(where= + IN(PersonWorkplace.q.WorkplaceID, + Select(Workplace.q.id, Workplace.q.id==SOME_ID))) |