Created
January 21, 2015 11:41
-
-
Save chanmix51/eb749f1eb47286109e3e to your computer and use it in GitHub Desktop.
case when in a projection definition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// … | |
public function createProjection() | |
{ | |
$age = <<<FIELD | |
case | |
when age(%published_at) > '1 year 1 day'::interval then date_trunc('year', age(%published_at)) | |
when age(%published_at) > '1 month 1 day'::interval then date_trunc('month', age(%published_at)) | |
when age(%published_at) > '1 day'::interval then date_trunc('day', age(%published_at)) | |
when age(%published_at) > '1 hour'::interval then date_trunc('hour', age(%published_at)) | |
else date_trunc('minutes', age(%published_at)) | |
end | |
FIELD; | |
return parent::createProjection() | |
->setField('age', $age, 'interval') | |
; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment