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

Using prepared statment results in error #385

Open
2 tasks
pdeva opened this issue Jul 19, 2023 · 3 comments
Open
2 tasks

Using prepared statment results in error #385

pdeva opened this issue Jul 19, 2023 · 3 comments

Comments

@pdeva
Copy link

pdeva commented Jul 19, 2023

Describe the bug
This code works perfectly fine:

       var role string

	found, err := db.From(TableAccountUsers).Select("role").Where(goqu.Ex{
		"user_id":    userId,
		"account_id": accountId,
	}).ScanValContext(ctx, &role)

However, if i add .Prepared(true) to it, it results in an error:

       var role string

	found, err := db.From(TableAccountUsers)..Prepared(true).Select("role").Where(goqu.Ex{
		"user_id":    userId,
		"account_id": accountId,
	}).ScanValContext(ctx, &role)

error:

{"level":"error","module":"pgx","err":"ERROR: syntax error at or near \")\" (SQLSTATE 42601)","name":"stmtcache_16","pid":56,"sql":"SELECT \"role\" FROM \"account_users\" WHERE ((\"account_id\" = ?) AND (\"user_id\" = ?)) LIMIT ?","time":0.522084,"time":"2023-07-19T12:00:44-07:00","message":"Prepare"}
{"level":"error","module":"pgx","args":[{"1082":1,"1114":1,"1184":1,"16":1,"17":1,"20":1,"21":1,"23":1,"26":1,"28":1,"29":1,"700":1,"701":1},"a59a0a44-49d3-4f77-ad48-45d48afa4138","77fdd86f-ff4f-4ca7-a40e-9a51ad490167",1],"err":"ERROR: syntax error at or near \")\" (SQLSTATE 42601)","pid":56,"sql":"SELECT \"role\" FROM \"account_users\" WHERE ((\"account_id\" = ?) AND (\"user_id\" = ?)) LIMIT ?","time":0.531333,"time":"2023-07-19T12:00:44-07:00","message":"Query"}

To Reproduce

        var role string

	found, err := db.From(TableAccountUsers)..Prepared(true).Select("role").Where(goqu.Ex{
		"user_id":    userId,
		"account_id": accountId,
	}).ScanValContext(ctx, &role)

Expected behavior
Should work without errors

Dialect:

  • [x ] postgres
  • mysql
  • sqlite3

Additional context
Add any other context about the problem here.

@ankitLiv
Copy link

ankitLiv commented Jan 12, 2024

I am also facing this issue, for postgres placeholder should be like '$1' in prepared statement. but it is looking like it is generating '?'

@ankitLiv
Copy link

@doug-martin

@ankitLiv
Copy link

I am able to solve this problem. I haven't import _ "github.com/doug-martin/goqu/v9/dialect/postgres" this. which internally registers Postgres Dialect

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

2 participants