]> git.openstreetmap.org Git - nominatim.git/blobdiff - sql/tables.sql
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / sql / tables.sql
index f3217d5afa6079bd378145032c67400cae47b2db..e2960aea0147f0069ea0edc0555dd2ed65615314 100644 (file)
@@ -10,7 +10,7 @@ drop table if exists import_osmosis_log;
 CREATE TABLE import_osmosis_log (
   batchend timestamp,
   batchseq integer,
-  batchsize integer,
+  batchsize bigint,
   starttime timestamp,
   endtime timestamp,
   event text
@@ -61,22 +61,32 @@ CREATE TABLE location_area (
   rank_search SMALLINT NOT NULL,
   rank_address SMALLINT NOT NULL,
   country_code VARCHAR(2),
-  isguess BOOL
+  isguess BOOL,
+  postcode TEXT,
+  centroid GEOMETRY(Point, 4326),
+  geometry GEOMETRY(Geometry, 4326)
   );
-SELECT AddGeometryColumn('location_area', 'centroid', 4326, 'POINT', 2);
-SELECT AddGeometryColumn('location_area', 'geometry', 4326, 'GEOMETRY', 2);
 
 CREATE TABLE location_area_large () INHERITS (location_area);
 
+DROP TABLE IF EXISTS location_area_country;
+CREATE TABLE location_area_country (
+  place_id BIGINT,
+  country_code varchar(2),
+  geometry GEOMETRY(Geometry, 4326)
+  ) {ts:address-data};
+CREATE INDEX idx_location_area_country_geometry ON location_area_country USING GIST (geometry) {ts:address-index};
+
+
 drop table IF EXISTS location_property CASCADE;
 CREATE TABLE location_property (
   place_id BIGINT,
   parent_place_id BIGINT,
   partition SMALLINT,
   housenumber TEXT,
-  postcode TEXT
+  postcode TEXT,
+  centroid GEOMETRY(Point, 4326)
   );
-SELECT AddGeometryColumn('location_property', 'centroid', 4326, 'POINT', 2);
 
 CREATE TABLE location_property_aux () INHERITS (location_property);
 CREATE INDEX idx_location_property_aux_place_id ON location_property_aux USING BTREE (place_id);
@@ -125,9 +135,9 @@ CREATE TABLE search_name (
   address_rank SMALLINT,
   name_vector integer[],
   nameaddress_vector integer[],
-  country_code varchar(2)
+  country_code varchar(2),
+  centroid GEOMETRY(Geometry, 4326)
   ) {ts:search-data};
-SELECT AddGeometryColumn('search_name', 'centroid', 4326, 'GEOMETRY', 2);
 CREATE INDEX idx_search_name_place_id ON search_name USING BTREE (place_id) {ts:search-index};
 
 drop table IF EXISTS place_addressline;
@@ -157,9 +167,9 @@ CREATE TABLE placex (
   wikipedia TEXT, -- calculated wikipedia article name (language:title)
   country_code varchar(2),
   housenumber TEXT,
-  postcode TEXT
+  postcode TEXT,
+  centroid GEOMETRY(Geometry, 4326)
   ) {ts:search-data};
-SELECT AddGeometryColumn('placex', 'centroid', 4326, 'GEOMETRY', 2);
 CREATE UNIQUE INDEX idx_place_id ON placex USING BTREE (place_id) {ts:search-index};
 CREATE INDEX idx_placex_osmid ON placex USING BTREE (osm_type, osm_id) {ts:search-index};
 CREATE INDEX idx_placex_linked_place_id ON placex USING BTREE (linked_place_id) {ts:address-index} WHERE linked_place_id IS NOT NULL;
@@ -197,8 +207,24 @@ CREATE TRIGGER place_before_delete BEFORE DELETE ON place
 CREATE TRIGGER place_before_insert BEFORE INSERT ON place
     FOR EACH ROW EXECUTE PROCEDURE place_insert();
 
-DROP SEQUENCE IF EXISTS seq_postcodes;
-CREATE SEQUENCE seq_postcodes start 1;
+-- Table for synthetic postcodes.
+DROP TABLE IF EXISTS location_postcode;
+CREATE TABLE location_postcode (
+  place_id BIGINT,
+  parent_place_id BIGINT,
+  rank_search SMALLINT,
+  rank_address SMALLINT,
+  indexed_status SMALLINT,
+  indexed_date TIMESTAMP,
+  country_code varchar(2),
+  postcode TEXT,
+  geometry GEOMETRY(Geometry, 4326)
+  );
+CREATE INDEX idx_postcode_geometry ON location_postcode USING GIST (geometry) {ts:address-index};
+GRANT SELECT ON location_postcode TO "{www-user}" ;
+
+CREATE TRIGGER location_postcode_before_update BEFORE UPDATE ON location_postcode
+    FOR EACH ROW EXECUTE PROCEDURE postcode_update();
 
 DROP TABLE IF EXISTS import_polygon_error;
 CREATE TABLE import_polygon_error (
@@ -209,10 +235,10 @@ CREATE TABLE import_polygon_error (
   name HSTORE,
   country_code varchar(2),
   updated timestamp,
-  errormessage text
+  errormessage text,
+  prevgeometry GEOMETRY(Geometry, 4326),
+  newgeometry GEOMETRY(Geometry, 4326)
   );
-SELECT AddGeometryColumn('import_polygon_error', 'prevgeometry', 4326, 'GEOMETRY', 2);
-SELECT AddGeometryColumn('import_polygon_error', 'newgeometry', 4326, 'GEOMETRY', 2);
 CREATE INDEX idx_import_polygon_error_osmid ON import_polygon_error USING BTREE (osm_type, osm_id);
 GRANT SELECT ON import_polygon_error TO "{www-user}";