From 4a9e7a1b1abce66d02bcff41911dafc71d54fbff Mon Sep 17 00:00:00 2001 From: Patrick O'brien Date: Mon, 19 Sep 2016 17:51:06 +1000 Subject: [PATCH] Fix upsert for mysql --- queries/query_builders.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/queries/query_builders.go b/queries/query_builders.go index 8997eaa..1595871 100644 --- a/queries/query_builders.go +++ b/queries/query_builders.go @@ -190,6 +190,17 @@ func BuildUpsertQueryMySQL(dia Dialect, tableName string, update, whitelist []st buf := strmangle.GetBuffer() defer strmangle.PutBuffer(buf) + if len(update) == 0 { + fmt.Fprintf( + buf, + "INSERT IGNORE INTO %s (%s) VALUES (%s)", + tableName, + strings.Join(whitelist, ", "), + strmangle.Placeholders(dia.IndexPlaceholders, len(whitelist), 1, 1), + ) + return buf.String() + } + fmt.Fprintf( buf, "INSERT INTO %s (%s) VALUES (%s) ON DUPLICATE KEY UPDATE ",