Using PRAGMAs as sources in SQLite in getting column names

删除回忆录丶 提交于 2019-12-08 15:05:15

问题


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:


Since SQLite 3.16.0 we can use PRAGMA functions

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
sqlite> select name from pragma_table_info('my_table');
name
----------
a
b


来源:https://stackoverflow.com/questions/2899105/using-pragmas-as-sources-in-sqlite-in-getting-column-names

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!