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

Postgres update join not working #961

Closed
edstef opened this issue Mar 11, 2024 · 2 comments
Closed

Postgres update join not working #961

edstef opened this issue Mar 11, 2024 · 2 comments
Labels

Comments

@edstef
Copy link

edstef commented Mar 11, 2024

I see in #908 that there is a feature for update query with join.
I updated to github.com/uptrace/bun v1.1.17 and I get no golang errors but do get errors from postgres:

pgdriver.Error{m:map[uint8]string{0x43:"42601", 0x46:"scan.l", 0x4c:"1192", 0x4d:"syntax error at or near \"INNER\"", 0x50:"72", 0x52:"scanner_yyerror"

My code:

_, err := m.db.NewUpdate().
    Model(&PlayerGameRelation{}).
    Set("state = ?", PLAYER_GAME_RELATION_STATES.QUIT).
    Join("INNER JOIN games ON player_game_relations.game = game.id").
    Where("player_game_relations.player = ? AND game.state = ?", playerId, gameState).
    Exec(context.Background())

In postgres it says to update join using FROM clause but bun doesn't support that on update query. From postgres logs the full statement is:

UPDATE "player_game_relations" AS "player_game_relation" SET state = 1 INNER JOIN game ON player_game_relations.game = game.id WHERE (player_game_relations.player = '7319998d-0223-4929-997f-ea667f587695' AND game.state = 0)```
@JunNishimura
Copy link
Contributor

@edstef

It seems to work as expected if you change the query to be passed to the Join method from the Join clause to the From clause as shown below(I can't guarantee that it will work correctly since I haven't actually tested it).

    Join("INNER JOIN games ON player_game_relations.game = game.id")
    ↓
    Join("From games ON player_game_relations.game = game.id")

Copy link

This issue has been automatically marked as stale because it has not had activity in the last 30 days. If there is no update within the next 7 days, this issue will be closed.

@github-actions github-actions bot added the stale label Nov 17, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants