-
Notifications
You must be signed in to change notification settings - Fork 123
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
Can i use RETURNING in INSERT? #83
Comments
It's recommended to build the SQL like this. ib := sqlbuilder.PostgreSQL.NewInsertBuilder()
ib.InsertInto("table").Cols("field").Values("some value")
// Use Build to add "RETURNING id" as a postfix.
sql, args := sqlbuilder.Build("$? RETURNING id;", ib)
println(sql)
println(args)
// Output:
// INSERT INTO table (field) VALUES (?) RETURNING id;
// [some value] |
Is this still the best way to do this? I'd like to use as many builders as I can without writing my own SQL. |
A (maybe) better way is to use ib.InsertInto("table").Cols("field").Values("some value")
// Add the RETURNING expression at the end of the INSERT statement.
ib.SQL("RETURNING id")
println(ib) // OUTPUT: INSERT INTO table (field) VALUES (?) RETURNING id As |
It's built-in to sqlite and a couple others. On subqueries within a transaction it's absolutely invaluable. |
Hello everyone. I am using SQLite and was also looking for this feature. I would be happy to see it as a builder method.
|
Since everyone here is interested in this feature, let me consider how to design it well. |
Using the 'RETURNING' syntax to get incremented ids in PostgresQL, how does it work in go-sqlbuilder?
The text was updated successfully, but these errors were encountered: