in_list function for PostgreSQL
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 SF_IN_LIST( | |
p_list1 text[], | |
p_list2 text[] | |
) RETURNS BOOLEAN AS $$ | |
DECLARE | |
w_is_in_list BOOLEAN := true; | |
BEGIN | |
IF p_list1 IS NULL OR p_list2 IS NULL THEN | |
RETURN false; | |
END IF; | |
IF array_length(p_list1, 1) = 0 OR array_length(p_list2, 1) = 0 THEN | |
RETURN false; | |
END IF; | |
FOR i IN 1..array_length(p_list1, 1) LOOP | |
IF p_list1[i] = ANY(p_list2) THEN | |
ELSE | |
w_is_in_list := false; | |
EXIT; | |
END IF; | |
END LOOP; | |
RETURN w_is_in_list; | |
END; | |
$$ LANGUAGE plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment