# SELECT auth,auth_key,type,place_name,fqn,alias,lat,lng
# INTO OUTFILE '/tmp/uk_gaz.csv'
# FIELDS TERMINATED BY ','
# ENCLOSED BY '"'
# ESCAPED BY '\\'
# LINES TERMINATED BY '\n'
# FROM paf_unified_gaz;
# 
# Had to run this as root in the end.
#

# SELECT auth,auth_key,type,place_name,fqn,aliases,ifnull(lat,''),ifnull(lng,'') INTO OUTFILE '/tmp/uk_gaz.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\n' FROM spatialdb.paf_unified_gaz;

SELECT auth,auth_key,type,place_name,fqn,concat('qzyf ',ifnull(fqn,'')),concat('qzyf ',ifnull(aliases,'')),ifnull(lat,''),ifnull(lng,'') INTO OUTFILE '/tmp/uk_gaz_with_geo.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\n' FROM spat.paf_unified_gaz where lat is not null and lng is not null;

SELECT auth,auth_key,type,place_name,fqn,aliases INTO OUTFILE '/tmp/uk_gaz_no_geo.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\n' FROM spatialdb.paf_unified_gaz where lat is NULL or lng is NULL;


# Then edit the generated file and add "authority_id,id,type,place_name,fqn,fqnidx,alias,centroid_lat,centroid_lon" to the top so solr knows which fields are in which cols
# SOLR Load command:
# curl http://localhost:8080/index/gaz/update/csv?stream.file=uk_gaz.csv&stream.contentType=text/plain;charset=utf-8&commit=true
