Created
November 26, 2015 11:39
-
-
Save EnTeQuAk/b65ad5627b6bff8668d4 to your computer and use it in GitHub Desktop.
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
select * from ( | |
select distinct on (id) * from ( | |
select core_feeditem.id, COALESCE(recipes_recipe_translation.republished_at, recipes_recipe_translation.published_at) as "ordering" | |
from core_feeditem | |
join recipes_recipe on core_feeditem.id = recipes_recipe.feeditem_ptr_id | |
join recipes_recipe_translation | |
on recipes_recipe.feeditem_ptr_id = recipes_recipe_translation.master_id | |
join unnest(array['de','en']) with ordinality as u(lang,priority) on recipes_recipe_translation.language_code=u.lang | |
union all | |
select core_feeditem.id, COALESCE(articles_article_translation.republished_at, articles_article_translation.published_at) as "ordering" | |
from core_feeditem | |
join articles_article on core_feeditem.id = articles_article.feeditem_ptr_id | |
join articles_article_translation | |
on articles_article.feeditem_ptr_id = articles_article_translation.master_id | |
join unnest(array['de','en']) with ordinality as u(lang,priority) on articles_article_translation.language_code=u.lang | |
) a | |
) b | |
order by ordering desc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment