我想执行此声明
CREATE TABLE Tab2 AS SELECT 1, "abc", 123456789.12 UNION SELECT 2, "def", 25090003;
在SQLite数据库上。如何明确定义生成的列类型?
顺便说一句:这是关于CREATE TABLE ... AS SELECT with discrete values with explicit column names
的后续问题答案 0 :(得分:0)
根据documentation,列类型来自SELECT中结果列的expression affinities。
1
或'abc'
之类的普通值没有亲和力;你必须用CAST
添加它:
CREATE TABLE Tab2 AS
SELECT CAST(1 AS INT) AS i,
CAST('abc' AS TEXT) as t,
CAST(123456789.12 AS REAL) AS r
UNION ALL SELECT 2, "def", 25090003 ...