From 694e42d6a1de36adba2702088be5aa5658072f7f Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 17 Nov 2020 19:11:16 +0800 Subject: [PATCH] Fix clause.IN with only one value of multiple rows --- clause/expression.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/clause/expression.go b/clause/expression.go index 40265ac6..b30c46b0 100644 --- a/clause/expression.go +++ b/clause/expression.go @@ -160,8 +160,13 @@ func (in IN) Build(builder Builder) { case 0: builder.WriteString(" IN (NULL)") case 1: - builder.WriteString(" = ") - builder.AddVar(builder, in.Values...) + if _, ok := in.Values[0].([]interface{}); !ok { + builder.WriteString(" = ") + builder.AddVar(builder, in.Values[0]) + break + } + + fallthrough default: builder.WriteString(" IN (") builder.AddVar(builder, in.Values...) @@ -173,9 +178,14 @@ func (in IN) NegationBuild(builder Builder) { switch len(in.Values) { case 0: case 1: - builder.WriteQuoted(in.Column) - builder.WriteString(" <> ") - builder.AddVar(builder, in.Values...) + if _, ok := in.Values[0].([]interface{}); !ok { + builder.WriteQuoted(in.Column) + builder.WriteString(" <> ") + builder.AddVar(builder, in.Values[0]) + break + } + + fallthrough default: builder.WriteQuoted(in.Column) builder.WriteString(" NOT IN (")