MySQL INSERT错误操作数应包含1列

时间:2016-06-29 15:32:28

标签: mysql insert mysql-error-1241

我有这个MySQL插入查询给了我cls $output = New-Object PSObject ### METRICS ### $metrics = New-Object PSObject # Current time date $lastRun = Get-Date -Format "HH:mm MM/dd/yyyy" $metrics | Add-Member -PassThru NoteProperty lastRun $lastRun # Get Avg CPU $cpu = (gwmi win32_processor | Measure-Object -property LoadPercentage -Average).Average $metrics | Add-Member -PassThru NoteProperty cpu $cpu # Get Available Memory $memory = (Get-Counter -counter "\Memory\Available MBytes").CounterSamples | Select-Object -expandProperty CookedValue # Get Total Memory $totalMem = ((gwmi CIM_PhysicalMemory).Capacity)[0] / 1048576 # Percent free Memory $freeMemory = [math]::round($memory / $totalMem, 2) * 100 $metrics | Add-Member -PassThru NoteProperty memory $freeMemory $output | Add-Member -PassThru NoteProperty metrics $metrics ### END METRICS ### ### DISKS ### # Get Disk Drives $drives = gwmi Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3} $disks = ## What should this be? ## foreach($drive in $drives) { $id = $drive.DeviceID $size = [math]::round($drive.Size / 1073741824, 2) $free = [math]::round($drive.FreeSpace / 1073741824, 2) $pct = [math]::round($free / $size, 2) * 100 #SHOW IN JSON $disks ## Add drive = $id, freeSpace = $pct - How? ## ## Not able to build a correct element here to add for JSON ## } $output | Add-Member -PassThru NoteProperty disks ##??$disks??# ### END DISKS ###

Error Code: 1241. Operand should contain 1 column(s)

它工作正常,如果我当时只尝试插入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, 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); 允许在单个语句中插入多条记录。有什么想法吗?

P.S。我知道查询是罗嗦的,但这很好,因为它是以编程方式生成的。

1 个答案:

答案 0 :(得分:2)

我的不好,你的查询还可以。你只是有一些错别字。

这里有一个额外的开放式大括号:( ( 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);