Search code examples
sqlitepragma

How do you get the number of columns in a SQLite File using PRAGMA?


I've tried using pragma table_info(test001) however that just returns another table where there's a row for every column. My issue is that, how do I count the rows? I've tried using

SELECT COUNT(*) FROM PRAGMA table_info(test001)
and
SELECT COUNT(CID) FROM PRAGMA table_info(test001)

However they both error out. Does anyone know how I could get an actual numerical value using PRAGMA? I read the documentation for table_info but it didn't help in figuring out how to actual get a value from it.


Solution

  • You can do this:

    select count(*) from pragma_table_info('tablename');
    

    You can find more info here: https://www.sqlite.org/pragma.html in the section PRAGMA functions