Open
Description
Describe the bug
If you try to insert row into a table with default values, there is no DEFAULT VALUES statement in the query itself. This causes problems, for example, if you want to conditionally clear rows you want to insert and have RETURNING statement.
To Reproduce
If applicable provide a small code snippet to reproduce the issue:
package main
import (
"fmt"
"github.com/doug-martin/goqu/v9"
_ "github.com/doug-martin/goqu/v9/dialect/sqlite3"
_ "github.com/mattn/go-sqlite3"
)
func main() {
ds := goqu.Dialect("sqlite3").
Insert("table").
Rows(goqu.Record{"foo": "bar"}).
Returning("id")
if true {
ds = ds.ClearRows()
}
str, args, err := ds.ToSQL()
fmt.Println(str, args, err)
}
Expected behavior
Expected:
INSERT INTO "table" DEFAULT VALUES RETURNING "id" [] <nil>
Actual:
INSERT INTO `table` RETURNING `id` [] <nil>
The code above with postgres dialect will have expected output.
Dialect:
- postgres
- mysql
- sqlite3
Additional context
Default values fragment for sqlite seems to have empty string for a value. Removing this option setting solves the problem. However, it is noted in the comments for this fragment that only postgres supports it:
The SQL fragment to use when generating insert sql and using DEFAULT VALUES (e. g. postgres="DEFAULT VALUES", mysql="", sqlite3=""). (DEFAULT=[] byte(" DEFAULT VALUES"))
Is there a reason for that? Thank you in advance.
Metadata
Assignees
Labels
No labels
Activity