Search code examples
mysqlinsertmysql-error-1241

MySQL INSERT Error Operand should contain 1 column


I have this MySQL insert query that is giving me a Error Code: 1241. Operand should contain 1 column(s).

INSERT INTO esjp_content
    ( esjp_content.primary_key, esjp_content.template_id, esjp_content.section_ref,
    esjp_content.position, esjp_content.indent, esjp_content.content,
    esjp_content.summary_id, esjp_content.role_ref, esjp_content.author_id,
    esjp_content.event_id, esjp_content.sys_time )
VALUES
    ( ( 3, 1, 1, 0, 0, 'Some test content.', 0, 1, 1, 69, UNIX_TIMESTAMP(NOW()) ),
    ( 4, 1, 1, 1, 1, 'Some test content2.', 0, 1, 1, 69, UNIX_TIMESTAMP(NOW()) ) )
ON DUPLICATE KEY UPDATE
    esjp_content.primary_key=VALUES(esjp_content.primary_key),
    esjp_content.template_id=VALUES(esjp_content.template_id),
    esjp_content.section_ref=VALUES(esjp_content.section_ref),
    esjp_content.position=VALUES(esjp_content.position),
    esjp_content.indent=VALUES(esjp_content.indent),
    esjp_content.content=VALUES(esjp_content.content),
    esjp_content.summary_id=VALUES(esjp_content.summary_id),
    esjp_content.role_ref=VALUES(esjp_content.role_ref),
    esjp_content.author_id=VALUES(esjp_content.author_id),
    esjp_content.event_id=VALUES(esjp_content.event_id),
    esjp_content.sys_time=VALUES(esjp_content.sys_time);

It works fine, if I only try to insert 1 record at at time, but I thought that INSERT allowed for inserting multiple records in a single statement. Any ideas?

P.S. I know the query is wordy, but that's fine, since it's generated programmatically.


Solution

  • My bad, your query is ok. You just have some typos.

    One extra open brace here: ( ( 3,

    And one closing brace here: 69, UNIX_TIMESTAMP(NOW()) ) )

    Guess if you fix that, everything should work fine.

    http://sqlfiddle.com/#!9/1e9f3f/1

    INSERT INTO esjp_content
        ( esjp_content.primary_key, esjp_content.template_id, esjp_content.section_ref,
        esjp_content.position, esjp_content.indent, esjp_content.content,
        esjp_content.summary_id, esjp_content.role_ref, esjp_content.author_id,
        esjp_content.event_id, esjp_content.sys_time )
    VALUES
        (  3, 1, 1, 0, 0, 'Some test content.', 0, 1, 1, 69, NOW() ),
        ( 4, 1, 1, 1, 1, 'Some test content2.', 0, 1, 1, 69, NOW() + INTERVAL 1 DAY ) 
    ON DUPLICATE KEY UPDATE
        esjp_content.primary_key=VALUES(esjp_content.primary_key),
        esjp_content.template_id=VALUES(esjp_content.template_id),
        esjp_content.section_ref=VALUES(esjp_content.section_ref),
        esjp_content.position=VALUES(esjp_content.position),
        esjp_content.indent=VALUES(esjp_content.indent),
        esjp_content.content='updated',
        esjp_content.summary_id=VALUES(esjp_content.summary_id),
        esjp_content.role_ref=VALUES(esjp_content.role_ref),
        esjp_content.author_id=VALUES(esjp_content.author_id),
        esjp_content.event_id=VALUES(esjp_content.event_id),
        esjp_content.sys_time=VALUES(esjp_content.sys_time);