【问题标题】:How to select specific column types in SQLite3?如何在 SQLite3 中选择特定的列类型?
【发布时间】:2021-09-29 04:10:42
【问题描述】:
PRAGMA table_info(myTable)

此查询选择表中的所有信息,例如:如果表中有 2 列,则此查询将选择所有列名、列类型等

我只想添加一个子句,即我想获取我在查询中定义的特定列的信息。

像这样:

PRAGMA table_info(myTable) where columnNames = 'a' and columnNames = 'b' // this is wrong query but I just mentioned it to make my question more clear.

我该怎么做?

【问题讨论】:

    标签: ios swift database sqlite select


    【解决方案1】:

    您可以在带有WHERE 子句的查询中使用pragma_table_info()

    SELECT * 
    FROM pragma_table_info('myTable') -- note the single quotes
    WHERE name IN ('a', 'b') -- equivalent: name = 'a' OR name = 'b'
    

    请参阅demo

    【讨论】:

    • @RehanAliKhan name 是包含列名的结果中的列名。
    猜你喜欢
    • 2016-04-04
    • 1970-01-01
    • 1970-01-01
    • 2017-07-28
    • 1970-01-01
    • 2018-01-28
    • 2012-05-22
    • 2013-07-13
    • 1970-01-01
    相关资源
    最近更新 更多