Created
October 25, 2021 23:32
-
-
Save beargiles/1691fce83ad964f91b9bc43e34dec5f9 to your computer and use it in GitHub Desktop.
PostgreSQL function checking whether a parameter is in a valid set of values
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
-- | |
-- Function that needs to explicitly check whether the 'color' value is valid | |
-- | |
CREATE OR REPLACE FUNCTION get_gluon(color text) RETURNS TEXT AS $$ | |
#print_strict_params on | |
DECLARE | |
duck TEXT; | |
BEGIN | |
IF color not in ('red', 'green', 'blue') THEN | |
RAISE EXCEPTION 'unknown color %', color; | |
END IF; | |
-- .... | |
return duck; | |
END; | |
$$ LANGUAGE plpgsql | |
IMMUTABLE | |
RETURNS NULL ON NULL INPUT | |
PARALLEL SAFE; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment