Created
June 27, 2014 17:58
-
-
Save happysundar/6de451e44cb32dcd0459 to your computer and use it in GitHub Desktop.
filtering out all non-null elements from an array in postgresql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH T1 AS ( | |
SELECT | |
program_id, | |
ARRAY [alias_title, | |
alias_title_2, | |
alias_title_3, | |
alias_title_4] AS title_array | |
FROM movies | |
), | |
T2 AS ( | |
SELECT | |
program_id, | |
unnest(title_array) AS alias_title | |
FROM T1 ) | |
SELECT | |
program_id, | |
array_agg(alias_title) | |
FROM t2 | |
WHERE alias_title IS NOT NULL | |
GROUP BY program_id | |
LIMIT 50; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment