3

我收到一个非常非描述性的错误:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'VALUES (order_site_id, order_id, business_email, business_domain, sm_type, activ' at line 1

这是插入/更新

INSERT INTO table 
(
    id,
    order_site_id,
    order_id,
    business_email,
    business_domain,
    sm_type,
    active,
    code,
    sm_auth,
    installed,
    created,
    cancelled,
    uninstalled,
    updated
) VALUES (
        1,
        2,
        1,
        'jd.daniel@domain.com',
        'domain.com',
        'farce',
        'N',
        'a3yhegy',
        '55f933dad8a389cf760d39df01df923e',
        '0000-00-00 00:00:00',
        '2013-02-20 11:21:00',
        '0000-00-00 00:00:00',
        '0000-00-00 00:00:00',
        '2013-02-20 11:21:00'
    ), (
        2,
        2,
        2,
        'bob.allen@domain.com',
        'domain.com',
        'farce',
        'N',
        'e4eqere',
        '08d2ab294466864d3453201be3e4a391',
        '0000-00-00 00:00:00',
        '2013-02-20 11:37:45',
        '0000-00-00 00:00:00',
        '0000-00-00 00:00:00',
        '2013-02-20 11:37:45'
    ), (
        3,
        2,
        3,
        'william.grey@domain.com',
        'domain.com',
        'farce',
        'N',
        '8yme3ud',
        'c52b2cf4a6a5ceab503fe71c45d9e5da',
        '0000-00-00 00:00:00',
        '2013-02-20 11:38:28',
        '0000-00-00 00:00:00',
        '0000-00-00 00:00:00',
        '2013-02-20 11:38:28'
    ), (
        4,
        2,
        4,
        'jane.doe@domain.com',
        'domain.com',
        'farce',
        'N',
        'zuzuquz',
        'c30dbfda67a0016d810b774e08e077c8',
        '0000-00-00 00:00:00',
        '2013-02-20 11:42:31',
        '0000-00-00 00:00:00',
        '0000-00-00 00:00:00',
        '2013-02-20 11:42:31'
    ), (
        5,
        2,
        5,
        'john.smith@domain.com',
        'domain.com',
        'farce',
        'N',
        'nyruqu4',
        'c376194d36d5706a6ca343dc3a06248d',
        '0000-00-0000:00:00',
        '2013-02-20 11:43:29',
        '0000-00-00 00:00:00',
        '0000-00-00 00:00:00',
        '2013-02-20 11:43:29'
) ON DUPLICATE KEY UPDATE VALUES (
    order_site_id,
    order_id,
    business_email,
    business_domain,
    sm_type,
    active,
    code,
    sm_auth,
    installed,
    created,
    cancelled,
    uninstalled,
    updated
);
4

1 回答 1

0

您不要将 VALUES 子句与 ON DUPLICATE KEY UPDATE 一起使用。

语法应该更像 UPDATE 语法:

INSERT INTO table (id, order_site_id, order_id, ...) 
VALUES (1, 2, 1, ...), (2, 2, 2, ...), ...more tuples...
ON DUPLICATE KEY UPDATE 
SET order_site_id = <expr>,
    order_id = <expr>,
    ...other column assignments...

请参阅http://dev.mysql.com/doc/refman/5.5/en/insert-on-duplicate.html

如果您只想在重复键的情况下保留现有的列值,则应考虑使用 INSERT IGNORE 而不是 ON DUPLICATE KEY UPDATE 和无操作更新。

于 2013-02-25T18:57:41.187 回答