Syntax error on MERGE statement

后端 未结 1 491
一向
一向 2020-12-07 05:17

I\'m trying to do a MERGE statement in Go:

query := \"MERGE staged ON (email=$1)\" +
\" WHEN NOT MATCHED THEN INSERT (email, secret, passwd, ts, newAcct)\" +         


        
相关标签:
1条回答
  • 2020-12-07 05:41

    MERGE is not supported by MySQL, The equivalent for that is

    INSERT ... ON DUPLICATE KEY UPDATE

    Try this,

    INSERT INTO tableName (email, secret, passwd, ts, newAcct) 
    VALUES ($1,$2,$3,$4,TRUE)
    ON DUPLICATE KEY UPDATE newAcct=TRUE, existingUser=NULL, secret=$2, ts=$4
    

    but be sure email is set as Primary Key or Unique.

    0 讨论(0)
提交回复
热议问题