Skip to content

Instantly share code, notes, and snippets.

@number5
Created November 25, 2011 03:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save number5/1392734 to your computer and use it in GitHub Desktop.
Save number5/1392734 to your computer and use it in GitHub Desktop.
array pop function for postgresql 8.4+
CREATE OR REPLACE FUNCTION array_pop(a anyarray, element character varying)
RETURNS anyarray
LANGUAGE plpgsql
AS $function$
DECLARE
result a%TYPE;
BEGIN
SELECT ARRAY(
SELECT b.e FROM (SELECT unnest(a)) AS b(e) WHERE b.e <> element) INTO result;
RETURN result;
END;
$function$
@drasill
Copy link

drasill commented May 21, 2012

Thank you, very useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment