Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an equivalent SELECT statement for PRAGMA table_info('mytable') in SQLite?

Tags:

sqlite

Is there an equivalent SELECT statement for PRAGMA table_info('mytable') in SQLite? Essentially, I would like to get the exact same result set as PRAGMA returns: cid, name, type, notnull, dflt_value, and pk. Although I know of the other alternative to getting this information via the C function sqlite3_table_column_metadata, I would prefer to use a SELECT statement.

like image 781
Ziminji Avatar asked Jul 31 '11 09:07

Ziminji


1 Answers

According to the doc

PRAGMAs that return results and that have no side-effects can be accessed from ordinary SELECT statements as table-valued functions. For each participating PRAGMA, the corresponding table-valued function has the same name as the PRAGMA with a 7-character "pragma_" prefix. The PRAGMA argument and schema, if any, are passed as arguments to the table-valued function.

For example, information about the columns in an index can be read using the index_info pragma as follows:

PRAGMA index_info('idx52'); Or, the same content can be read using:

SELECT * FROM pragma_index_info('idx52');

shouldn't this do the trick?

like image 128
cuda12 Avatar answered Oct 22 '22 03:10

cuda12