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

Subqueries in Update().Set() with Postgres dialect generates incorrect query #413

Open
1 of 3 tasks
afv1 opened this issue Mar 25, 2024 · 0 comments
Open
1 of 3 tasks

Comments

@afv1
Copy link

afv1 commented Mar 25, 2024

Describe the bug
Subqueries in Update().Set() with Postgres dialect generates incorrect query: '?' instead of '$1'

To Reproduce

testDS := goqu.Dialect("postgres").Update("test.table_1").
	Set(goqu.Record{
		"sub": goqu.Select("id").
			From("test.table_1").
			Where(goqu.C("from").Eq(from)),
	}).
	From("test.table_2").
	Where(
		goqu.C("test_id").Eq(id),
		goqu.C("to").Eq(to),
	)

fmt.Println(testDS.Prepared(true).ToSQL())
	
// Output:
// UPDATE "test"."table_1" SET "sub"=(SELECT "id" FROM "test"."table_1" WHERE ("from" = ?)) FROM "test"."table_2"
// WHERE (("test_id" = $2) AND ("to" = $3)) [1 12 2] <nil>

Expected behavior
Expected output:

UPDATE "test"."table1" SET "huy"=(SELECT "id" FROM "t"."subtable_1" WHERE ("from" = $1)) FROM "test"."table_2" WHERE (("test_id" = $2) AND ("to" = $3)) [1 12 2] <nil>

But first parameter interpolated incorrectly for PG syntax '?'. Looks like it caused by sybquery in Setect(...)

Dialect:

  • postgres
  • mysql
  • sqlite3

Additional context
Add any other context about the problem here.

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