Skip to content

Instantly share code, notes, and snippets.

@number5
Created November 25, 2011 03:00
Show Gist options
  • Select an option

  • Save number5/1392734 to your computer and use it in GitHub Desktop.

Select an option

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

drasill commented May 21, 2012

Copy link
Copy Markdown

Thank you, very useful.

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