Created
November 25, 2011 03:00
-
-
Save number5/1392734 to your computer and use it in GitHub Desktop.
array pop function for postgresql 8.4+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, very useful.