Jerry Krinock <[EMAIL PROTECTED]> wrote:
> My query:
> 
> DELETE FROM `table1` WHERE (`id`=1 OR `id`=2 OR `id`=3 OR ... OR `id`=N)
> 
> using the C API.  When N exceeds 999, I get an error stating that the  
> maximum depth of 1000 has been exceeded, and this is documented in 
> http://www.sqlite.org/limits.html 
> , item 5.
> 
> Of course, I could fix this by doing multiple queries when N>999, but  
> my code is very nicely encapsulated as is, and that change would make  
> it all yucky.  So I'd like other alternatives.

The WHERE expression is parsed as follows:

   (...(((id=1 OR id=2) OR id=3) OR id=4) OR ...) OR id=N)

If you draw this as a tree, you find that, indeed, it is N
levels deep.  But by explicit use of parentheses, you can
force a balanced tree with a depth of only logN.

   (...((id=1 OR id=2) OR (id=3 OR id=4)) OR (...)...)

But instead of all that trouble, why not just say:

   id IN (1,2,3,4,5,...,N)

The latter is not only more efficient, but easier for human
readers to understand as well.

> 
> 1.  I would describe my query as "1000 clauses wide".  I'm not nesting  
> anything "1000 levels deep".  Is there a way to rewrite my query and  
> make it work?
> 
> 2.  Documentation implies that I can change the parameter  
> SQLITE_MAX_EXPR_DEPTH from the default of 1000.  But I can't find  
> SQLITE_MAX_EXPR_DEPTH in sqlite3.h.  Seems to be neither a compiler  
> macro nor a global.  (Mac OS X 10.5, sqlite 3.4.0).  Where is it?
> 

Look in sqliteLimit.h

--
D. Richard Hipp <[EMAIL PROTECTED]>


-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to