Convert integer to text in SQLite's SELECT query?

后端 未结 1 464
我寻月下人不归
我寻月下人不归 2020-12-13 18:22

I would like to create a SELECT query that would return numbers from column in integer format as a text format - can I do it in SQLite?

1条回答
  •  旧巷少年郎
    2020-12-13 18:52

    SQLite supports CAST and:

    Casting an INTEGER or REAL value into TEXT renders the value as if via sqlite3_snprintf() except that the resulting TEXT uses the encoding of the database connection.

    So you can do things like this:

    select cast(some_integer_column as text) from some_table;
    

    Or, depending on what you're trying to do, you could just treat the numbers as strings and let SQLite coerce the types as it sees fit:

    select some_int || ' pancakes' from some_table;
    select some_int || '' from some_table;
    

    0 讨论(0)
提交回复
热议问题