我正在使用MySQL 5.0.88/Coldfusion
并且有一个临时表,我正在加载一个CSV文件。此表经过验证,然后导入主数据库。
我需要检查临时表中的重复导入。我正在检查临时表:
<cfquery datasource="db">
UPDATE import_temp
SET error= "true", errorMsg = "missing info"
WHERE user = <cfqueryparam value = "#Session.user#" cfsqltype="cf_sql_varchar" maxlength="13">
AND error = "false"
AND info = ""
</cfquery>
问题:
是否可以在临时表上检查重复的ID,如下所示:
<cfquery datasource="db">
UPDATE import_temp
SET error = "true", errorMsg = "duplicate id"
WHERE user = <cfqueryparam value = "#Session.user#" cfsqltype="cf_sql_varchar" maxlength="13">
AND error = "false"
AND id IN (SELECT i.id FROM import_temp AS i WHERE i.id = id)
</cfquery>
现在这不起作用,但有没有办法让它工作并将错误字段设置为false?或者是加载CSV文件时使用on duplicate key
的唯一方法吗?
答案 0 :(得分:1)
UPDATE import_temp
SET error = "true", errorMsg = "duplicate id"
WHERE user = <cfqueryparam value = "#Session.user#" cfsqltype="cf_sql_varchar" maxlength="13">
AND error = "false"
AND id IN (SELECT id FROM permanent WHERE import_temp.id = id)
答案 1 :(得分:0)
确定。现在就这样做......:
<cfquery datasource="db" name="dups">
SELECT ean
FROM import_pricat_csv
WHERE iln = <cfqueryparam value = "#Session.loginID#" cfsqltype="cf_sql_varchar" maxlength="13">
AND fehler = "nein"
AND ean IN (
SELECT ean
FROM import_pricat_csv
GROUP BY ean
HAVING count(ean) > 1
)
</cfquery>
<cfif dups.recordcount GT 0>
<cfloop query="dups">
<cfquery datasource="db">
UPDATE import_pricat_csv
SET fehler = "ja", fehlertext = "EAN doppelt"
WHERE ean = dups.ean
</cfquery>
</cfloop>
</cfif>
不好,但似乎有效。