Skip to content

Instantly share code, notes, and snippets.

@garethflowers
Last active May 3, 2021 21:48
Show Gist options
  • Select an option

  • Save garethflowers/2e626d6e53b8f07c8bd9 to your computer and use it in GitHub Desktop.

Select an option

Save garethflowers/2e626d6e53b8f07c8bd9 to your computer and use it in GitHub Desktop.
Returns an array with no NULL or '' (emtpy string) values
CREATE OR REPLACE FUNCTION array_filter_blanks(
ANYARRAY
)
RETURNS ANYARRAY
LANGUAGE sql
IMMUTABLE
STRICT
AS $$
SELECT ARRAY(
SELECT x
FROM UNNEST( $1 ) AS x
WHERE x IS NOT NULL
AND x <> ''
);
$$;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment