Skip to content

Instantly share code, notes, and snippets.

@jjn1056
Created May 8, 2019 21:25
Show Gist options
  • Save jjn1056/d0a962d42262e21317326ec1e7afe7f7 to your computer and use it in GitHub Desktop.
Save jjn1056/d0a962d42262e21317326ec1e7afe7f7 to your computer and use it in GitHub Desktop.
catme=> select
catme-> CASE
catme-> WHEN COALESCE(name, school) = '' THEN 'EMPTY STRING'
catme-> WHEN COALESCE(name, school) = NULL THEN 'NULL1'
catme-> WHEN COALESCE(name, school) IS NULL THEN 'NULL2'
catme-> ELSE COALESCE(name, school)
catme-> END as institution
catme-> from (
catme(> SELECT 'name' as name, 'school' as school
catme(> UNION ALL
catme(> SELECT NULL as name, NULL as school
catme(> UNION ALL
catme(> SELECT '' as name, '' as school
catme(> UNION ALL
catme(> SELECT '1' as name, '' as school
catme(> UNION ALL
catme(> SELECT '2' as name, NULL as school
catme(> UNION ALL
catme(> SELECT '' as name, '3' as school
catme(> UNION ALL
catme(> SELECT NULL as name, '4' as school
catme(> ) as stuff(name, school);
institution
--------------
name
NULL2
EMPTY STRING
1
2
EMPTY STRING
4
(7 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment