Skip to content

Binding issue with ? operator using join->on with Postgres #56872

@elsconfairmed

Description

@elsconfairmed

Laravel Version

11.45.2

PHP Version

8.3

Database Driver & Version

psql (PostgreSQL) 14.10 (Homebrew)

Description

I got the same Problem described in this Issue when I try to use the ? with joins.

There error is SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "$1"...

It looks like the ? does not get escape with ??

After some digging i found that for basic where('column', '?', $key) this was fixed in Illuminate\Database\Query\Grammars\Grammer::295

Possible workarounds that I found were to use the customOperators() function to add the escaped operators or to write raw queries every time you deal with json columns

Steps To Reproduce

Model::leftJoin('table_2', fn($join) => $join->on(DB::raw("model_table.jsonb->'ids'"),'?','table_2.id'))->get();

The raw query is needed so that the ' not get replaced with '' and break the query

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions