Skip to content

Commit ca3df7a

Browse files
authored
Support compileJsonOverlaps (#7381)
1 parent 11dbaf1 commit ca3df7a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Query/Grammars/PostgresGrammar.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,16 @@ protected function compileJsonContains($column, $value): string
335335
return '(' . $column . ')::jsonb @> ' . $value;
336336
}
337337

338+
/**
339+
* Compile a "JSON overlaps" statement into SQL.
340+
*/
341+
protected function compileJsonOverlaps(string $column, string $value): string
342+
{
343+
$column = str_replace('->>', '->', $this->wrap($column));
344+
345+
return 'EXISTS ( SELECT 1 FROM jsonb_array_elements((' . $column . ')::jsonb) AS elem1, jsonb_array_elements(' . $value . '::jsonb) AS elem2 WHERE elem1 = elem2)';
346+
}
347+
338348
/**
339349
* Compile a "JSON length" statement into SQL.
340350
*

0 commit comments

Comments
 (0)