]> git.openstreetmap.org Git - nominatim.git/blob - sql/tables.sql
Merge branch 'separate-compilation' of https://github.com/eyusupov/Nominatim into...
[nominatim.git] / sql / tables.sql
1 drop table if exists import_status;
2 CREATE TABLE import_status (
3   lastimportdate timestamp NOT NULL,
4   sequence_id integer,
5   indexed boolean
6   );
7 GRANT SELECT ON import_status TO "{www-user}" ;
8
9 drop table if exists import_osmosis_log;
10 CREATE TABLE import_osmosis_log (
11   batchend timestamp,
12   batchseq integer,
13   batchsize bigint,
14   starttime timestamp,
15   endtime timestamp,
16   event text
17   );
18
19 CREATE TABLE new_query_log (
20   type text,
21   starttime timestamp,
22   ipaddress text,
23   useragent text,
24   language text,
25   query text,
26   searchterm text,
27   endtime timestamp,
28   results integer,
29   format text,
30   secret text
31   );
32 CREATE INDEX idx_new_query_log_starttime ON new_query_log USING BTREE (starttime);
33 GRANT INSERT ON new_query_log TO "{www-user}" ;
34 GRANT UPDATE ON new_query_log TO "{www-user}" ;
35 GRANT SELECT ON new_query_log TO "{www-user}" ;
36
37 GRANT SELECT ON TABLE country_name TO "{www-user}";
38 GRANT SELECT ON TABLE gb_postcode TO "{www-user}";
39 GRANT SELECT ON TABLE us_postcode TO "{www-user}";
40
41 drop table IF EXISTS word;
42 CREATE TABLE word (
43   word_id INTEGER,
44   word_token text,
45   word text,
46   class text,
47   type text,
48   country_code varchar(2),
49   search_name_count INTEGER,
50   operator TEXT
51   ) {ts:search-data};
52 CREATE INDEX idx_word_word_token on word USING BTREE (word_token) {ts:search-index};
53 GRANT SELECT ON word TO "{www-user}" ;
54 DROP SEQUENCE IF EXISTS seq_word;
55 CREATE SEQUENCE seq_word start 1;
56
57 drop table IF EXISTS location_area CASCADE;
58 CREATE TABLE location_area (
59   place_id BIGINT,
60   keywords INTEGER[],
61   partition SMALLINT,
62   rank_search SMALLINT NOT NULL,
63   rank_address SMALLINT NOT NULL,
64   country_code VARCHAR(2),
65   isguess BOOL,
66   postcode TEXT,
67   centroid GEOMETRY(Point, 4326),
68   geometry GEOMETRY(Geometry, 4326)
69   );
70
71 CREATE TABLE location_area_large () INHERITS (location_area);
72
73 DROP TABLE IF EXISTS location_area_country;
74 CREATE TABLE location_area_country (
75   place_id BIGINT,
76   country_code varchar(2),
77   geometry GEOMETRY(Geometry, 4326)
78   ) {ts:address-data};
79 CREATE INDEX idx_location_area_country_geometry ON location_area_country USING GIST (geometry) {ts:address-index};
80
81
82 drop table IF EXISTS location_property CASCADE;
83 CREATE TABLE location_property (
84   place_id BIGINT,
85   parent_place_id BIGINT,
86   partition SMALLINT,
87   housenumber TEXT,
88   postcode TEXT,
89   centroid GEOMETRY(Point, 4326)
90   );
91
92 CREATE TABLE location_property_aux () INHERITS (location_property);
93 CREATE INDEX idx_location_property_aux_place_id ON location_property_aux USING BTREE (place_id);
94 CREATE INDEX idx_location_property_aux_parent_place_id ON location_property_aux USING BTREE (parent_place_id);
95 CREATE INDEX idx_location_property_aux_housenumber_parent_place_id ON location_property_aux USING BTREE (parent_place_id, housenumber);
96 GRANT SELECT ON location_property_aux TO "{www-user}";
97
98 CREATE TABLE location_property_tiger (
99   place_id BIGINT,
100   parent_place_id BIGINT,
101   startnumber INTEGER,
102   endnumber INTEGER,
103   partition SMALLINT,
104   linegeo GEOMETRY,
105   interpolationtype TEXT,
106   postcode TEXT);
107 GRANT SELECT ON location_property_tiger TO "{www-user}";
108
109 drop table if exists location_property_osmline;
110 CREATE TABLE location_property_osmline (
111     place_id BIGINT NOT NULL,
112     osm_id BIGINT,
113     parent_place_id BIGINT,
114     geometry_sector INTEGER,
115     indexed_date TIMESTAMP,
116     startnumber INTEGER,
117     endnumber INTEGER,
118     partition SMALLINT,
119     indexed_status SMALLINT,
120     linegeo GEOMETRY,
121     interpolationtype TEXT,
122     address HSTORE,
123     postcode TEXT,
124     country_code VARCHAR(2)
125   ){ts:search-data};
126 CREATE UNIQUE INDEX idx_osmline_place_id ON location_property_osmline USING BTREE (place_id) {ts:search-index};
127 CREATE INDEX idx_osmline_geometry_sector ON location_property_osmline USING BTREE (geometry_sector) {ts:address-index};
128 CREATE INDEX idx_osmline_linegeo ON location_property_osmline USING GIST (linegeo) {ts:search-index};
129 GRANT SELECT ON location_property_osmline TO "{www-user}";
130
131 drop table IF EXISTS search_name;
132 CREATE TABLE search_name (
133   place_id BIGINT,
134   importance FLOAT,
135   search_rank SMALLINT,
136   address_rank SMALLINT,
137   name_vector integer[],
138   nameaddress_vector integer[],
139   country_code varchar(2),
140   centroid GEOMETRY(Geometry, 4326)
141   ) {ts:search-data};
142 CREATE INDEX idx_search_name_place_id ON search_name USING BTREE (place_id) {ts:search-index};
143
144 drop table IF EXISTS place_addressline;
145 CREATE TABLE place_addressline (
146   place_id BIGINT,
147   address_place_id BIGINT,
148   distance FLOAT,
149   cached_rank_address SMALLINT,
150   fromarea boolean,
151   isaddress boolean
152   ) {ts:search-data};
153 CREATE INDEX idx_place_addressline_place_id on place_addressline USING BTREE (place_id) {ts:search-index};
154
155 drop table if exists placex;
156 CREATE TABLE placex (
157   place_id BIGINT NOT NULL,
158   parent_place_id BIGINT,
159   linked_place_id BIGINT,
160   importance FLOAT,
161   indexed_date TIMESTAMP,
162   geometry_sector INTEGER,
163   rank_address SMALLINT,
164   rank_search SMALLINT,
165   partition SMALLINT,
166   indexed_status SMALLINT,
167   LIKE place INCLUDING CONSTRAINTS,
168   wikipedia TEXT, -- calculated wikipedia article name (language:title)
169   country_code varchar(2),
170   housenumber TEXT,
171   postcode TEXT,
172   centroid GEOMETRY(Geometry, 4326)
173   ) {ts:search-data};
174 CREATE UNIQUE INDEX idx_place_id ON placex USING BTREE (place_id) {ts:search-index};
175 CREATE INDEX idx_placex_osmid ON placex USING BTREE (osm_type, osm_id) {ts:search-index};
176 CREATE INDEX idx_placex_linked_place_id ON placex USING BTREE (linked_place_id) {ts:address-index} WHERE linked_place_id IS NOT NULL;
177 CREATE INDEX idx_placex_rank_search ON placex USING BTREE (rank_search, geometry_sector) {ts:address-index};
178 CREATE INDEX idx_placex_geometry ON placex USING GIST (geometry) {ts:search-index};
179 CREATE INDEX idx_placex_adminname on placex USING BTREE (make_standard_name(name->'name')) {ts:address-index} WHERE osm_type='N' and rank_search < 26;
180 CREATE INDEX idx_placex_wikidata on placex USING BTREE ((extratags -> 'wikidata')) {ts:address-index} WHERE extratags ? 'wikidata' and class = 'place' and osm_type = 'N' and rank_search < 26;
181
182 DROP SEQUENCE IF EXISTS seq_place;
183 CREATE SEQUENCE seq_place start 1;
184 GRANT SELECT on placex to "{www-user}" ;
185 GRANT SELECT ON search_name to "{www-user}" ;
186 GRANT SELECT on place_addressline to "{www-user}" ;
187 GRANT SELECT ON seq_word to "{www-user}" ;
188 GRANT SELECT ON planet_osm_ways to "{www-user}" ;
189 GRANT SELECT ON planet_osm_rels to "{www-user}" ;
190 GRANT SELECT on location_area to "{www-user}" ;
191
192 -- Table for synthetic postcodes.
193 DROP TABLE IF EXISTS location_postcode;
194 CREATE TABLE location_postcode (
195   place_id BIGINT,
196   parent_place_id BIGINT,
197   rank_search SMALLINT,
198   rank_address SMALLINT,
199   indexed_status SMALLINT,
200   indexed_date TIMESTAMP,
201   country_code varchar(2),
202   postcode TEXT,
203   geometry GEOMETRY(Geometry, 4326)
204   );
205 CREATE INDEX idx_postcode_geometry ON location_postcode USING GIST (geometry) {ts:address-index};
206 GRANT SELECT ON location_postcode TO "{www-user}" ;
207
208 DROP TABLE IF EXISTS import_polygon_error;
209 CREATE TABLE import_polygon_error (
210   osm_id BIGINT,
211   osm_type CHAR(1),
212   class TEXT NOT NULL,
213   type TEXT NOT NULL,
214   name HSTORE,
215   country_code varchar(2),
216   updated timestamp,
217   errormessage text,
218   prevgeometry GEOMETRY(Geometry, 4326),
219   newgeometry GEOMETRY(Geometry, 4326)
220   );
221 CREATE INDEX idx_import_polygon_error_osmid ON import_polygon_error USING BTREE (osm_type, osm_id);
222 GRANT SELECT ON import_polygon_error TO "{www-user}";
223
224 DROP TABLE IF EXISTS import_polygon_delete;
225 CREATE TABLE import_polygon_delete (
226   osm_id BIGINT,
227   osm_type CHAR(1),
228   class TEXT NOT NULL,
229   type TEXT NOT NULL
230   );
231 CREATE INDEX idx_import_polygon_delete_osmid ON import_polygon_delete USING BTREE (osm_type, osm_id);
232 GRANT SELECT ON import_polygon_delete TO "{www-user}";
233
234 DROP SEQUENCE IF EXISTS file;
235 CREATE SEQUENCE file start 1;
236
237 -- null table so it won't error
238 -- deliberately no drop - importing the table is expensive and static, if it is already there better to avoid removing it
239 CREATE TABLE wikipedia_article (
240     language text NOT NULL,
241     title text NOT NULL,
242     langcount integer,
243     othercount integer,
244     totalcount integer,
245     lat double precision,
246     lon double precision,
247     importance double precision,
248     osm_type character(1),
249     osm_id bigint,
250     wd_page_title text,
251     instance_of text
252 );
253 ALTER TABLE ONLY wikipedia_article ADD CONSTRAINT wikipedia_article_pkey PRIMARY KEY (language, title);
254 CREATE INDEX idx_wikipedia_article_osm_id ON wikipedia_article USING btree (osm_type, osm_id);
255
256 CREATE TABLE wikipedia_redirect (
257     language text,
258     from_title text,
259     to_title text
260 );
261 ALTER TABLE ONLY wikipedia_redirect ADD CONSTRAINT wikipedia_redirect_pkey PRIMARY KEY (language, from_title);
262