-
Notifications
You must be signed in to change notification settings - Fork 911
Support Named Arguments in stdlib #1699
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
Comments
You can use pgx.NamedArgs with stdlib. package main
import (
"database/sql"
"fmt"
"log"
"os"
"github.com/jackc/pgx/v5"
_ "github.com/jackc/pgx/v5/stdlib"
)
func main() {
db, err := sql.Open("pgx", os.Getenv("DATABASE_URL"))
if err != nil {
log.Fatal(err)
}
defer db.Close()
var a, b, c string
err = db.QueryRow("select @a::text, @b::text, @c::text", pgx.NamedArgs{"a": "foo", "b": "bar", "c": "baz"}).Scan(&a, &b, &c)
if err != nil {
log.Fatal(err)
}
fmt.Println(a, b, c)
} |
Thanks for answering. I know I can use |
I don't understand. It is using |
Sorry for not being clear. I want to use |
Ah. I see now. Some databases such as MSSQL directly support named parameters. PostgreSQL does not. As far as I can tell, While it is presumably possible to support it, I'm reluctant to do so.
|
Thanks. My plan was to convert slice of |
That is how you would implement this, but I am still doubtful that it is a good idea. As mentioned before, I'm reluctant to automagically rewrite the SQL query. But in addition, the value of supporting |
I thought that you do that when
Mostly my OCD of using only stdlib :) I'm closing this issue, thanks for explaining. |
I consider using |
Is your feature request related to a problem? Please describe.
The stdlib driver does not support sql.NamedArg.
Describe the solution you'd like
I'd like statements like
INSERT INTO journal (time, login, content) VALUES (:time, :login, :content);
(or with@
instead of:
) to work.Describe alternatives you've considered
I can use "pgx" directory with
pgx.NamedArgs
Additional context
Nope.
The text was updated successfully, but these errors were encountered: