操作数应包含1个关于插入& amp;列的列。选择

时间:2012-07-08 09:12:54

标签: python mysql

"insert into NodeProfileSections (profile_no, tpl_section_no) 
select (np.profile_no, tps.tpl_section_no)
from NodeProfile np, TemplateProfileSection tps, TemplateProfile tp 
where np.hostname = '%s' AND np.role = '%s' AND tp.tpl_profile_no = tps.tpl_profile_no 
AND tp.tpl_name = '%s' AND tp.role = '%s' AND tps.tpl_section_name = '%s';" 
%(hostname, role, template_name, role, section_name)

error_message = 'Operand should contain 1 column(s)'

如何解决这个问题?

1 个答案:

答案 0 :(得分:5)

从内部选择中删除括号。

q = """INSERT INTO 
             NodeProfileSections (profile_no,tpl_section_no)
       SELECT
             np.profile_no
             ,tps.tpl_section_no
       FROM
             NodeProfile np
             ,TemplateProfileSection tps
             ,TemplateProfile tp
       WHERE
             np.hostname = '%s'
             AND np.role = '%s'
             AND tp.tpl_profile_no = tps.tpl_profile_no
             AND tpl.tpl_name = '%s'
             AND tp.role = '%s'
             AND tps.tpl_section_name = '%s'
"""