duange051858 2014-02-22 20:32
浏览 56
已采纳

具有哈希列名称的CREATE TABLE语句中的MySQL语法错误

I am parsing xls/csv files into database. For each file I have one table with columns named by hashes of file column names.

For columns

  • Nazwisko
  • Imię
  • Adres1
  • Adres2
  • Miasto
  • Telefon
  • Kod
  • Email
  • Województwo

I have SQL:

CREATE TABLE premium_import_temp_worksheet_9 (
id                       INTEGER NOT NULL AUTO_INCREMENT,
f37c4446e4a882972cd3a80053dd795f VARCHAR(255),
d5bfdd6746ff1a364399acb6e6526b7a VARCHAR(255),
f7e2db7542ea17f0fcc1a46ee21f860b VARCHAR(255),
7161b0ab070daf8e20a2b62f2ef13b81 VARCHAR(255),
4f4e297d754b67e7a104f58b2bcdb850 VARCHAR(255),
0975cf6baccb3862c31522c2b5b8fabc VARCHAR(255),
d1c0419824dea874935502cf6d7c946f VARCHAR(255),
ce8ae9da5b7cd6c3df2929543a9af92d VARCHAR(255),
d7f1213d49993b7ce9ce02463ea1eeda VARCHAR(255),
                 PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci

and everything is executed without any errors, but for:

  • Company Name
  • Phone
  • sffd
  • sdf
  • sdfff

I have:

CREATE TABLE premium_import_temp_worksheet_8 (
id                       INTEGER NOT NULL AUTO_INCREMENT,
e7b47c58815acf1d3afa59a84b5db7fb VARCHAR(255),
bcc254b55c4a1babdf1dcb82c207506b VARCHAR(255),
6e87a4f6ea8244d7e04cb52e495d6693 VARCHAR(255),
d9729feb74992cc3482b350163a1a010 VARCHAR(255),
c90e651df62a9057d9bc8f48b42da7d0 VARCHAR(255),
                 PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci

And error:

mysqlt error: [1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '6e87a4f6ea8244d7e04cb52e495d6693 VARCHAR(255), d9729feb74992cc3482b350163a1a010 ' at line 5] in EXECUTE("CREATE TABLE premium_import_temp_worksheet_7 ( id INTEGER NOT NULL AUTO_INCREMENT, e7b47c58815acf1d3afa59a84b5db7fb VARCHAR(255), bcc254b55c4a1babdf1dcb82c207506b VARCHAR(255), 6e87a4f6ea8244d7e04cb52e495d6693 VARCHAR(255), d9729feb74992cc3482b350163a1a010 VARCHAR(255), c90e651df62a9057d9bc8f48b42da7d0 VARCHAR(255), PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci")

I don't know what is the difference between syntaxes of these two statements. Please help.

  • 写回答

2条回答 默认 最新

  • duanqiechui2378 2014-02-22 20:44
    关注

    What you are observing appears to be a bug. As excerpted from the documentation:

    Identifiers may begin with a digit but unless quoted may not consist solely of digits.

    The confusion appears to be due to the fact that "6e87" is a valid number, even though it does not consist entirely of digits. This is exponential notation. For some reason, although an unquoted identifier can start with a digit, it cannot start with a number in exponential notation.

    This is easy enough to fix by quoting the identifiers with either backticks or double quotes.

    EDIT:

    You can replicate the problem with these two simple queries:

    select 6 as 5_1
    
    select 6 as 5e1
    
    select 6 as 5f1
    
    select 6 as 5e1f
    

    The first and third work. The second correctly fails because the identifier is a number (in exponential form). The last fails incorrectly. By the way, I think it is a bad idea to start identifiers with numbers, but that is a separate matter from MySQL behaving the way it is documented to behave.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line