Parse error near line 6: no such column: ostrich
le" , "10" , 4 UNION SELECT "ostrich" , "500"
error here ---^
CREATE TABLE animals AS
SELECT "dog" AS name, "20" AS weight, 4 AS legs UNION
SELECT "cat" , "10" , 4 UNION
SELECT "penguin" , "300" , 2 UNION
SELECT "t-rex" , "12000" , 2 UNION
SELECT "parrot" , "6" , 2 UNION
SELECT "crocodile" , "10" , 4 UNION
SELECT "ostrich" , "500" , 2;
简而言之,所使用的“鸵鸟”被视为列名称。 “鸵鸟”(与“鸵鸟”相对)将被视为字面值。
按照:-
字符串常量是通过将字符串括在单引号(')中形成的。字符串中的单引号可以通过将两个单引号放在一行中进行编码 - 就像 Pascal 中一样。不支持使用反斜杠字符的 C 样式转义,因为它们不是标准 SQL。 https://www.sqlite.org/lang_expr.html#literal_values_constants_
你想要的是使用:-
CREATE TABLE animals AS
SELECT 'dog' AS name, '20' AS weight, 4 AS legs UNION
SELECT 'cat' , '10' , 4 UNION
SELECT 'penguin' , '300' , 2 UNION
SELECT 't-rex' , '12000' , 2 UNION
SELECT 'parrot' , '6' , 2 UNION
SELECT 'crocodile' , '10' , 4 UNION
SELECT 'ostrich' , '500' , 2;