1

我正在使用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 像这样?on duplicate key或者是加载 CSV 文件时使用的唯一方法?

4

2 回答 2

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)
于 2012-10-18T18:58:15.247 回答
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>

不好,但似乎工作。

于 2012-10-18T19:44:20.520 回答