From 2c10e75af6f35d7d39bda183be1c8dca2dc02fe0 Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Fri, 13 May 2016 06:51:13 -0400 Subject: [PATCH] cast return value of obs_getboundaryid to text --- scripts/generate_fixtures.py | 14 ++++++++++---- src/pg/sql/44_observatory_geometries.sql | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/scripts/generate_fixtures.py b/scripts/generate_fixtures.py index 25360e9..3c93e8d 100644 --- a/scripts/generate_fixtures.py +++ b/scripts/generate_fixtures.py @@ -47,6 +47,7 @@ fixtures = [ ('us.census.spielman_singleton_segments.X10', 'us.census.tiger.census_tract', '2009 - 2013'), ('us.zillow.AllHomes_Zhvi', 'us.census.tiger.zcta5', '2014-01'), ('us.zillow.AllHomes_Zhvi', 'us.census.tiger.zcta5', '2016-03'), + ('whosonfirst.wof_country_geom', 'whosonfirst.wof_country_geom', '2016'), ] unique_tables = set() @@ -75,10 +76,15 @@ with open('src/pg/test/fixtures/load_fixtures.sql', 'w') as outfile: for tablename, colname, boundary_id in unique_tables: if 'zcta5' in boundary_id: - where = '11%' + where = '\'11%\'' + compare = 'LIKE' + elif 'whosonfirst' in boundary_id: + where = '(\'85632785\',\'85633051\',\'85633111\',\'85633147\',\'85633253\',\'85633267\')' + compare = 'IN' else: - where = '36047%' - print ' '.join([select_star(tablename), "WHERE {} LIKE '{}'".format(colname, where)]) - cdb.dump(' '.join([select_star(tablename), "WHERE {} LIKE '{}'".format(colname, where)]), + where = '\'36047%\'' + compare = 'LIKE' + print ' '.join([select_star(tablename), "WHERE {}::text {} {}".format(colname, compare, where)]) + cdb.dump(' '.join([select_star(tablename), "WHERE {}::text {} {}".format(colname, compare, where)]), tablename, outfile, schema='observatory') dropfiles.write('DROP TABLE IF EXISTS observatory.{};\n'.format(tablename)) diff --git a/src/pg/sql/44_observatory_geometries.sql b/src/pg/sql/44_observatory_geometries.sql index 2867be3..1d6cf6b 100644 --- a/src/pg/sql/44_observatory_geometries.sql +++ b/src/pg/sql/44_observatory_geometries.sql @@ -161,9 +161,9 @@ BEGIN RAISE NOTICE 'target_table: %, geoid_colname: %', target_table, geoid_colname; - -- return name of geometry id column + -- return geometry id column value EXECUTE format( - 'SELECT %I + 'SELECT %I::text FROM observatory.%I WHERE ST_Intersects($1, the_geom) LIMIT 1', geoid_colname, target_table)