2
"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)'

如何解决这个问题呢?

4

1 回答 1

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'
"""
于 2012-07-08T09:21:37.883 回答