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

[5.8] Fix UPDATE and DELETE queries with join bindings on PostgreSQL #29306

Merged
merged 1 commit into from Jul 27, 2019

Conversation

@staudenmeir
Copy link
Contributor

commented Jul 26, 2019

On PostgreSQL, Laravel implements UPDATE and DELETE queries with joins by adding their constraints after the WHERE constraints. If both clauses have bindings, their order is incorrect:

DB::table('comments')
    ->join('posts', function ($join) {
        $join->on('posts.id', '=', 'comments.commentable_id')
            ->where('comments.commentable_type', 'App\Post');
    })
    ->where('posts.active', 0)
    ->delete();
delete from "comments" USING "posts"
where "posts"."active" = 'App\Post'
  and "posts"."id" = "comments"."commentable_id"
  and "comments"."commentable_type" = 0

We have to put the where bindings before the join bindings.

We could also swap the constraints in the generated SQL, but that's quite cumbersome.

@derekmd

This comment has been minimized.

Copy link
Contributor

commented Jul 26, 2019

#18694 Related issue?

@staudenmeir

This comment has been minimized.

Copy link
Contributor Author

commented Jul 26, 2019

@derekmd Both issues are related to PostgreSQL's syntax for UPDATE and DELETE queries, but they aren't directly related to each other. I'm also working on a solution for #18694.

@taylorotwell taylorotwell merged commit 518dcf9 into laravel:5.8 Jul 27, 2019

2 checks passed

continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@staudenmeir staudenmeir deleted the staudenmeir:pgsql-bindings branch Jul 28, 2019

@driesvints

This comment has been minimized.

Copy link
Member

commented Aug 1, 2019

@staudenmeir thanks for all your help lately with these database issues! 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.