开发者

Using PRAGMAs as sources in SQLite in getting column names

开发者 https://www.devze.com 2022-12-31 05:44 出处:网络
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

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 t开发者_如何学Che SELECT docs with sqlite.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消