Skip to content

Instantly share code, notes, and snippets.

@EnTeQuAk
Created November 26, 2015 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EnTeQuAk/b65ad5627b6bff8668d4 to your computer and use it in GitHub Desktop.
Save EnTeQuAk/b65ad5627b6bff8668d4 to your computer and use it in GitHub Desktop.
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