Skip to content

Instantly share code, notes, and snippets.

@jaymzcd
Created August 18, 2010 13:12
Show Gist options
  • Select an option

  • Save jaymzcd/534679 to your computer and use it in GitHub Desktop.

Select an option

Save jaymzcd/534679 to your computer and use it in GitHub Desktop.
/* Add a blank column at the start for the id field */
sed -e 's/\(.*\)/,\1/g' zipcodes.txt > /tmp/codes.txt && mv /tmp/codes.txt zipcodes.txt
/* Table structure for the zipcode data from
http://www.populardata.com/zipcode_database.html */
BEGIN;
CREATE TABLE `zipsearch_zipcodeentry` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`zipcode` varchar(5) NOT NULL,
`latitude` numeric(9, 6) NOT NULL,
`longitude` numeric(9, 6) NOT NULL,
`city_name` varchar(25) NOT NULL,
`state` varchar(2) NOT NULL,
`county` varchar(25) NOT NULL,
`format` varchar(50) NOT NULL
);
COMMIT;
/* Load in and done \o/ */
LOAD DATA LOCAL INFILE 'zipcodes.txt' INTO TABLE zipsearch_zipcodeentry
FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment