Skip to content

Instantly share code, notes, and snippets.



Created Nov 26, 2015
What would you like to do?
select * from (
select distinct on (id) * from (
select, COALESCE(recipes_recipe_translation.republished_at, recipes_recipe_translation.published_at) as "ordering"
from core_feeditem
join recipes_recipe on = 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, COALESCE(articles_article_translation.republished_at, articles_article_translation.published_at) as "ordering"
from core_feeditem
join articles_article on = 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