代码之家  ›  专栏  ›  技术社区  ›  thomas

aurora MySQL5.7插入失败

  •  1
  • thomas  · 技术社区  · 7 年前

    我好像搞不懂这个。我来自SQL Server世界,但希望它也能工作。

    insert into active_directory (ad_account,email,distinguished_name,employee_id,manager_distinguished_name,display_name,terminated)
    select
        ad_account,
        email,
        distinguished_name,
        employee_id,
        manager_distinguished_name,
        display_name,
        case when distinguished_name like '%Terminations%' then 1 else 0 end as terminated
    from
        active_directory_staging
    

    失败并出现此错误:

    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 'terminated)
    select
        ad_account,
        email,
        distinguished_name,
        employee_id,
        mana' at line 1
    

    如果我移除 terminated

    如果我只运行select部分(对于终止的列有case语句和没有case语句),它就可以正常工作。

    active_directory

    CREATE TABLE `active_directory` (
      `ad_account` varchar(100) COLLATE latin1_general_ci DEFAULT NULL,
      `display_name` varchar(100) COLLATE latin1_general_ci DEFAULT NULL,
      `email` varchar(100) COLLATE latin1_general_ci DEFAULT NULL,
      `distinguished_name` varchar(200) COLLATE latin1_general_ci DEFAULT NULL,
      `employee_id` varchar(100) COLLATE latin1_general_ci DEFAULT NULL,
      `manager_distinguished_name` varchar(200) COLLATE latin1_general_ci DEFAULT NULL,
      `terminated` bit(1) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   JAC2703    7 年前

    MySQL有一堆不能用作列名/别名的保留字。

    不幸的是, terminated

    摘自 https://dev.mysql.com/doc/refman/5.7/en/keywords.html :

    • ...
    • 诱人的
    • 终止(R)
    • 文本
    • ...