Skip to content

Instantly share code, notes, and snippets.

@EnTeQuAk

EnTeQuAk/feed.sql

Created Nov 26, 2015
Embed
What would you like to do?
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