一个关于sqlite错误的问题:没有这样的列

nnsrf1az  于 12个月前  发布在  SQLite
关注(0)|答案(1)|浏览(188)

在Windiws PowerShell中使用sqlite3 -init ex.sql时,出现错误:

Parse error near line 6: no such column: ostrich
  le"   , "10"        , 4          UNION     SELECT "ostrich"     , "500"
                                      error here ---^

在我的ex.sql中,只是编码

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;

拜托,我刚开始学SQL,这个问题困扰我很久了

lmvvr0a8

lmvvr0a81#

简而言之,"ostrich"被认为是列名的标识符。'ostrich'将被视为预期的文字值。

  • “鳄鱼”、“鹦鹉”……只不过鸵鸟虽然是最后一次出现,却是第一次被报道。

根据:-
字符串常量是通过将字符串括在单引号(')中形成的。字符串中的单引号可以通过将两个单引号放在一行中来编码-就像Pascal中一样。不支持使用反斜杠字符的C样式转义,因为它们不是标准SQL。https://www.sqlite.org/lang_expr.html#literal_values_constants_
更多关于双v单引号的信息请访问:-https://www.sqlite.org/quirks.html#double_quoted_string_literals_are_accepted。
你想要的是用途:-

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;

相关问题