diff --git a/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php b/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php index 2eacd5ff3cc2..f5866b320a1e 100755 --- a/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php +++ b/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php @@ -34,6 +34,20 @@ protected function whereDate(Builder $query, $where) return $this->wrap($where['column']).'::date '.$where['operator'].' '.$value; } + /** + * Compile a "where time" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereTime(Builder $query, $where) + { + $value = $this->parameter($where['value']); + + return $this->wrap($where['column']).'::time '.$where['operator'].' '.$value; + } + /** * Compile a date based where clause. * diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index dcc6906d75f6..6b6fe8cf1f82 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -340,11 +340,19 @@ public function testWhereTimeOperatorOptionalMySql() $this->assertEquals([0 => '22:00'], $builder->getBindings()); } + public function testWhereTimePostgres() + { + $builder = $this->getPostgresBuilder(); + $builder->select('*')->from('users')->whereTime('created_at', '>=', '22:00'); + $this->assertEquals('select * from "users" where "created_at"::time >= ?', $builder->toSql()); + $this->assertEquals([0 => '22:00'], $builder->getBindings()); + } + public function testWhereTimeOperatorOptionalPostgres() { $builder = $this->getPostgresBuilder(); $builder->select('*')->from('users')->whereTime('created_at', '22:00'); - $this->assertEquals('select * from "users" where extract(time from "created_at") = ?', $builder->toSql()); + $this->assertEquals('select * from "users" where "created_at"::time = ?', $builder->toSql()); $this->assertEquals([0 => '22:00'], $builder->getBindings()); }