10000 Account for insert/upsert with where clause · sqlc-dev/sqlc-gen-python@d1a001d · GitHub
[go: up one dir, main page]

Skip to content

Commit d1a001d

Browse files
committed
Account for insert/upsert with where clause
1 parent 746594d commit d1a001d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

internal/gen.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,8 @@ func buildQueryTree(ctx *pyTmplCtx, i *importer, source string) *pyast.Node {
889889
case ":one":
890890
fetchrow := connMethodNode("fetchrow", q.ConstantName, q.ArgNodes()...)
891891
f.Body = append(f.Body, assignNode("row", poet.Await(fetchrow)))
892-
if strings.HasPrefix(q.ConstantName, "INSERT") || strings.HasPrefix(q.ConstantName, "UPSERT") {
892+
if !strings.Contains(strings.ToUpper(q.SQL), "WHERE ") &&
893+
(strings.HasPrefix(q.ConstantName, "INSERT") || strings.HasPrefix(q.ConstantName, "UPSERT")) {
893894
f.Returns = q.Ret.Annotation()
894895
} else {
895896
f.Body = append(f.Body, poet.Node(

0 commit comments

Comments
 (0)
0