Skip to content

Instantly share code, notes, and snippets.

@klapuch
Created December 3, 2019 12:22
Show Gist options
  • Save klapuch/23d24cbe6139912ae3d9f8e1b7b3a0df to your computer and use it in GitHub Desktop.
Save klapuch/23d24cbe6139912ae3d9f8e1b7b3a0df to your computer and use it in GitHub Desktop.
array_reverse function for postgres
CREATE FUNCTION array_reverse(anyarray) RETURNS anyarray RETURNS NULL ON NULL INPUT AS
$BODY$
SELECT array_agg(result.value ORDER BY ordinality DESC) FROM unnest($1) WITH ORDINALITY AS result(value);
$BODY$
LANGUAGE sql IMMUTABLE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment