我有这个MySQL插入查询,给我一个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);
它工作得很好,如果我一次只尝试插入1条记录,但我认为INSERT
允许在单个语句中插入多条记录。什么好主意吗?
注:我知道这个查询很冗长,但是没关系,因为它是通过编程生成的。
我的错,你的查询是好的。你只是有些错别字。
这里多一个大括号:( ( 3,
这里还有一个右括号:69, UNIX_TIMESTAMP(NOW()) ) )
我想如果你修复了这个问题,一切都会好起来的。
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);