Skip to content

Commit

Permalink
make any column searchable in postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
m-bymike committed Sep 19, 2018
1 parent caa7d53 commit 4eaae64
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Query/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function whereBasicLike(Builder $query, $where)
{
$value = $this->parameter($where['value']);

return $this->wrap($where['column']).' :: text '.$where['operator'].' '.$value;
return $this->wrap($where['column']).'::text '.$where['operator'].' '.$value;
}

/**
Expand Down
23 changes: 23 additions & 0 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,29 @@ public function testWhereTimePostgres()
$this->assertEquals([0 => '22:00'], $builder->getBindings());
}

public function testWhereLikePostgres()
{
$builder = $this->getPostgresBuilder();
$builder->select('*')->from('users')->where('id', 'like', '1');
$this->assertEquals('select * from "users" where "id"::text like ?', $builder->toSql());
$this->assertEquals([0 => '1'], $builder->getBindings());

$builder = $this->getPostgresBuilder();
$builder->select('*')->from('users')->where('id', 'ilike', '1');
$this->assertEquals('select * from "users" where "id"::text ilike ?', $builder->toSql());
$this->assertEquals([0 => '1'], $builder->getBindings());

$builder = $this->getPostgresBuilder();
$builder->select('*')->from('users')->where('id', 'not like', '1');
$this->assertEquals('select * from "users" where "id"::text not like ?', $builder->toSql());
$this->assertEquals([0 => '1'], $builder->getBindings());

$builder = $this->getPostgresBuilder();
$builder->select('*')->from('users')->where('id', 'not ilike', '1');
$this->assertEquals('select * from "users" where "id"::text not ilike ?', $builder->toSql());
$this->assertEquals([0 => '1'], $builder->getBindings());
}

public function testWhereDateSqlite()
{
$builder = $this->getSQLiteBuilder();
Expand Down

0 comments on commit 4eaae64

Please sign in to comment.