Created
November 14, 2012 15:33
-
-
Save jeremyFreeAgent/4072795 to your computer and use it in GitHub Desktop.
field
This file contains hidden or 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
-- Function: field(anyelement, anyarray) | |
-- DROP FUNCTION field(anyelement, anyarray); | |
CREATE OR REPLACE FUNCTION field(anyelement, anyarray) | |
RETURNS integer AS | |
$BODY$ | |
SELECT | |
COALESCE((SELECT i | |
FROM generate_series(1, array_upper($2, 1)) gs(i) | |
WHERE $2[i] = $1), | |
0); | |
$BODY$ | |
LANGUAGE sql STABLE | |
COST 100; | |
ALTER FUNCTION field(anyelement, anyarray) | |
OWNER TO root; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment