Created
September 4, 2017 14:58
-
-
Save spaghetti-/46034076e52fc03c846a127d3acf0b5e to your computer and use it in GitHub Desktop.
Convert singapore postcodes to districts
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 singapore_postcode_to_district (code text, out district_num int, out district_name text) | |
as $$ | |
begin | |
case substring(code from 1 for 2)::int | |
when 01, 02, 03, 04, 05, 06 then | |
district_num := 1; | |
district_name := 'Raffles Place, Cecil, Marina, People''s Park'; | |
when 07, 08 then | |
district_num := 2; | |
district_name := 'Anson, Tanjong Pagar'; | |
when 14,15, 16 then | |
district_num := 3; | |
district_name := 'Queenstown, Tiong Bahru'; | |
when 09, 10 then | |
district_num := 4; | |
district_name := 'Telok Blangah, Harbourfront'; | |
when 11, 12, 13 then | |
district_num := 5; | |
district_name := 'Pasir Panjang, Hong Leong Garden, Clementi New Town'; | |
when 17 then | |
district_num := 6; | |
district_name := 'High Street, Beach Road (part)'; | |
when 18, 19 then | |
district_num := 7; | |
district_name := 'Middle Road, Golden Mile'; | |
when 20, 21 then | |
district_num := 8; | |
district_name := 'Little India'; | |
when 22, 23 then | |
district_num := 9; | |
district_name := 'Orchard, Cairnhill, River Valley'; | |
when 24, 25, 26, 27 then | |
district_num := 10; | |
district_name := 'Ardmore, Bukit Timah, Holland Road, Tanglin'; | |
when 28, 29, 30 then | |
district_num := 11; | |
district_name := 'Watten Estate, Novena, Thomson'; | |
when 31, 32, 33 then | |
district_num := 12; | |
district_name := 'Balestier, Toa Payoh, Serangoon'; | |
when 34, 35, 36, 37 then | |
district_num := 13; | |
district_name := 'Macpherson, Braddell'; | |
when 38, 39, 40, 41 then | |
district_num := 14; | |
district_name := 'Geylang, Eunos'; | |
when 42, 43, 44, 45 then | |
district_num := 15; | |
district_name := 'Katong, Joo Chiat, Amber Road'; | |
when 46, 47, 48 then | |
district_num := 16; | |
district_name := 'Bedok, Upper East Coast, Eastwood, Kew Drive'; | |
when 49, 50, 81 then | |
district_num := 17; | |
district_name := 'Loyang, Changi'; | |
when 51, 52 then | |
district_num := 18; | |
district_name := 'Tampines, Pasir Ris'; | |
when 53, 54, 55, 82 then | |
district_num := 19; | |
district_name := 'Serangoon Garden, Hougang, Ponggol'; | |
when 56, 57 then | |
district_num := 20; | |
district_name := 'Bishan, Ang Mo Kio'; | |
when 58, 59 then | |
district_num := 21; | |
district_name := 'Upper Bukit Timah, Clementi Park, Ulu Pandan'; | |
when 60, 61, 62, 63, 64 then | |
district_num := 22; | |
district_name := 'Jurong'; | |
when 65, 66, 67, 68 then | |
district_num := 23; | |
district_name := 'Hillview, Dairy Farm, Bukit Panjang, Choa Chu Kang'; | |
when 69, 70, 71 then | |
district_num := 24; | |
district_name := 'Lim Chu Kang, Tengah'; | |
when 72, 73 then | |
district_num := 25; | |
district_name := 'Kranji, Woodgrove'; | |
when 77, 78 then | |
district_num := 26; | |
district_name := 'Upper Thomson, Springleaf'; | |
when 75, 76 then | |
district_num := 27; | |
district_name := 'Yishun, Sembawang'; | |
when 79, 80 then | |
district_num := 28; | |
district_name := 'Seletar'; | |
else | |
end case; | |
end; | |
$$ language plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment