Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite3 default insertion values #437

Open
1 of 3 tasks
MichaelSBoop opened this issue Dec 9, 2024 · 0 comments
Open
1 of 3 tasks

sqlite3 default insertion values #437

MichaelSBoop opened this issue Dec 9, 2024 · 0 comments

Comments

@MichaelSBoop
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant