Skip to content

Commit 5025ae3

Browse files
Cockroach delete limit (#697)
* DELETE FROM must have LIMIT support CockroachDB is not able to deal well with massive deletes and their recommended approach is to batch delete statements. Thus, support for LIMIT statement is a must in the adapter. * Updated tests
1 parent 8e61801 commit 5025ae3

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

adapter/cockroachdb/template.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ const (
123123
DELETE
124124
FROM {{.Table | compile}}
125125
{{.Where | compile}}
126+
{{if .Limit}}
127+
LIMIT {{.Limit}}
128+
{{end}}
126129
`
127130
adapterUpdateLayout = `
128131
UPDATE

adapter/cockroachdb/template_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,9 @@ func TestTemplateDelete(t *testing.T) {
259259
`DELETE FROM "artist" WHERE (id > 5)`,
260260
b.DeleteFrom("artist").Where("id > 5").String(),
261261
)
262+
263+
assert.Equal(
264+
`DELETE FROM "artist" WHERE (id > 5) LIMIT 10`,
265+
b.DeleteFrom("artist").Where("id > 5").Limit(10).String(),
266+
)
262267
}

0 commit comments

Comments
 (0)