Skip to content

Unable to use update between two tables in postgresql using Query Builder #54223

@Thavarajan

Description

@Thavarajan

Laravel Version

11 It might even exist from version 6

PHP Version

8.2

Database Driver & Version

postgres

Description

Hi team,
First of all thanks for this illuminated framework, found a bug for PostgreSQL update

DB::table('post')
  ->leftJoin('post_history', function ($join) {
      $join->on('post_history.post_id', '=', 'post.id');
  })
  ->where('post_history.post_status', postStatus::assigned)
  ->update([
      "post.last_comment" => DB::raw("post_history.comments")
  ]);

This query is working in Laravel 5.8, after migrating to laravel 11 this is not working
probably this commit

illuminate/database@4e1130c

make the above code unusable

Steps To Reproduce

Create the following table in any postgres database

post table with id, comment, last_comment
post_history table with id, post_id, post_status, comments

fill both tables with some record

run the code below

  DB::table('post')
        ->leftJoin('post_history', function ($join) {
            $join->on('post_history.post_id', '=', 'post.id');
        })
        ->where('post_history.post_status', postStatus::assigned)
        ->update([
            "post.last_comment" => DB::raw("post_history.comments")
        ]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions