Room/SQLite 别名的静态值
Room/SQLite Static Value for Alias
我希望在不存在部门列的情况下执行类似以下操作(这只是一个示例):
SELECT name, 'IT' as department FROM employees_table
name department
---------- ----------
John IT
Mike IT
Sally IT
当我尝试此操作时,出现以下错误:
error: no viable alternative at input
我知道这适用于其他数据库,但显然 Room/SQLite。有人可以用线索棒打我并帮助我实现这个目标吗?
谢谢。
看起来我的列名是 SQLite 关键字。呸!
实际代码看起来更像:
SELECT name, 'Running' as action FROM example_table
将其更改为以下内容解决了问题:
SELECT name, 'Running' as 'action' FROM example_table
我希望在不存在部门列的情况下执行类似以下操作(这只是一个示例):
SELECT name, 'IT' as department FROM employees_table
name department
---------- ----------
John IT
Mike IT
Sally IT
当我尝试此操作时,出现以下错误:
error: no viable alternative at input
我知道这适用于其他数据库,但显然 Room/SQLite。有人可以用线索棒打我并帮助我实现这个目标吗?
谢谢。
看起来我的列名是 SQLite 关键字。呸!
实际代码看起来更像:
SELECT name, 'Running' as action FROM example_table
将其更改为以下内容解决了问题:
SELECT name, 'Running' as 'action' FROM example_table