views:

35

answers:

1

Problem:

I want to do this operation

select name from pragma table_info(my_awesome_table)

However, it yields a syntax error. I have the sneaking suspicion this is possible, but it doesn't seem to be documented as usable in the SELECT docs with sqlite.

+1  A: 

Pragmas are SQLite-specific extension to SQL, it has a special syntax:

sqlite> create table my_table (a int, b TEXT);
sqlite> .headers ON
sqlite> .mode columns
sqlite> pragma table_info(my_table);
cid         name        type        notnull     dflt_value  pk
----------  ----------  ----------  ----------  ----------  ----------
0           a           int         0                       0
1           b           TEXT        0                       0

You can not specify columns, and you can not use pragmas in a subquery.

newtover
Just for closure on my part, can you offer any citations for that?
Paul Nathan
@Paul Nathan: `pragma-stmt` (http://sqlite.org/syntaxdiagrams.html#pragma-stmt) is used by `sql-stmt` only, as opposed to `select-stmt` (http://sqlite.org/syntaxdiagrams.html#select-stmt), definition of which is recursive.
newtover