Created
February 17, 2012 09:57
-
-
Save takinbo/1852307 to your computer and use it in GitHub Desktop.
PostgreSQL function to determine network prefix from a phone number
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 network_operator(msisdn text) | |
RETURNS text AS | |
$$ | |
DECLARE | |
operator TEXT; | |
BEGIN | |
IF msisdn ~ '^(0|234)(703|706|803|806|810|813|816)\\d+$' THEN | |
operator := 'MTN'; | |
ELSEIF msisdn ~ '^(0|234)(705|805|807|815)\\d+$' THEN | |
operator := 'GLO'; | |
ELSEIF msisdn ~ '^(0|234)(708|802|808|812)\\d+$' THEN | |
operator := 'AIRTEL'; | |
ELSEIF msisdn ~ '^(0|234)(809|817|818)\\d+$' THEN | |
operator := 'ETISALAT'; | |
ELSE | |
operator := 'UNKNOWN'; | |
END IF; | |
RETURN operator; | |
END | |
$$ | |
LANGUAGE plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment