Is it possible to get the maximum number of columns supported from sqlite3
at runtime? This database limitation is established with a compile-time variable SQLITE_MAX_COLUMN
(see limits). The default is normally 2000 columns.
I'm looking for something accessible from either the Python or SQL interface.
A simple but inefficient way to do this from Python:
This appears to be impossible in practical terms (i.e. without a very expensive brute-force approach along the lines of dan04's rather brilliant answer).The source (1, 2) for the
sqlite3
module contains no reference either toSQLITE_MAX_COLUMN
or to compile-time limits in general; neither does there appear to be any way to access them from within the SQL interface.UPDATE:
A simple modification of dan04's solution to use a binary search speeds things up considerably:
Running the code above through
timeit.repeat()
:... which comes to an average run-time of 30.76 / 150 = 0.205 seconds (on a 2.6 GHz quad-core machine) - not exactly fast, but likely more usable than the 15-20 seconds of the "kick it 'til it breaks" counting-from-one method.