Skip to content

Instantly share code, notes, and snippets.

@sonOfRa
Created April 17, 2020 07:45
Show Gist options
  • Save sonOfRa/92bcc3f35ca188185dc7a2b0876c9700 to your computer and use it in GitHub Desktop.
Save sonOfRa/92bcc3f35ca188185dc7a2b0876c9700 to your computer and use it in GitHub Desktop.
SELECT id,
CASE
WHEN :language = ANY (keys) THEN :language
WHEN 'en' = ANY (keys) THEN 'en'
WHEN 'de' = ANY (keys) THEN 'de'
END AS locale,
name -> locale
FROM ingredient_type,
akeys(name) AS keys
SELECT id,
CASE
WHEN :language = ANY (keys) THEN :language
WHEN 'en' = ANY (keys) THEN 'en'
WHEN 'de' = ANY (keys) THEN 'de'
END AS locale,
COALESCE(name -> :language, COALESCE(name -> 'en', name -> 'de'))
FROM ingredient_type,
akeys(name) AS keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment