Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save happysundar/6de451e44cb32dcd0459 to your computer and use it in GitHub Desktop.
Save happysundar/6de451e44cb32dcd0459 to your computer and use it in GitHub Desktop.
filtering out all non-null elements from an array in postgresql
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