]> git.openstreetmap.org Git - nominatim.git/blob - sql/tables.sql
move trigger creation later in setup
[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'),rank_search) {ts:address-index} WHERE osm_type='N' and rank_search < 26;
180
181 DROP SEQUENCE IF EXISTS seq_place;
182 CREATE SEQUENCE seq_place start 1;
183 GRANT SELECT on placex to "{www-user}" ;
184 GRANT SELECT ON search_name to "{www-user}" ;
185 GRANT SELECT on place_addressline to "{www-user}" ;
186 GRANT SELECT ON seq_word to "{www-user}" ;
187 GRANT SELECT ON planet_osm_ways to "{www-user}" ;
188 GRANT SELECT ON planet_osm_rels to "{www-user}" ;
189 GRANT SELECT on location_area to "{www-user}" ;
190
191 -- Table for synthetic postcodes.
192 DROP TABLE IF EXISTS location_postcode;
193 CREATE TABLE location_postcode (
194   place_id BIGINT,
195   parent_place_id BIGINT,
196   rank_search SMALLINT,
197   rank_address SMALLINT,
198   indexed_status SMALLINT,
199   indexed_date TIMESTAMP,
200   country_code varchar(2),
201   postcode TEXT,
202   geometry GEOMETRY(Geometry, 4326)
203   );
204 CREATE INDEX idx_postcode_geometry ON location_postcode USING GIST (geometry) {ts:address-index};
205 GRANT SELECT ON location_postcode TO "{www-user}" ;
206
207 DROP TABLE IF EXISTS import_polygon_error;
208 CREATE TABLE import_polygon_error (
209   osm_id BIGINT,
210   osm_type CHAR(1),
211   class TEXT NOT NULL,
212   type TEXT NOT NULL,
213   name HSTORE,
214   country_code varchar(2),
215   updated timestamp,
216   errormessage text,
217   prevgeometry GEOMETRY(Geometry, 4326),
218   newgeometry GEOMETRY(Geometry, 4326)
219   );
220 CREATE INDEX idx_import_polygon_error_osmid ON import_polygon_error USING BTREE (osm_type, osm_id);
221 GRANT SELECT ON import_polygon_error TO "{www-user}";
222
223 DROP TABLE IF EXISTS import_polygon_delete;
224 CREATE TABLE import_polygon_delete (
225   osm_id BIGINT,
226   osm_type CHAR(1),
227   class TEXT NOT NULL,
228   type TEXT NOT NULL
229   );
230 CREATE INDEX idx_import_polygon_delete_osmid ON import_polygon_delete USING BTREE (osm_type, osm_id);
231 GRANT SELECT ON import_polygon_delete TO "{www-user}";
232
233 DROP SEQUENCE IF EXISTS file;
234 CREATE SEQUENCE file start 1;
235
236 -- null table so it won't error
237 -- deliberately no drop - importing the table is expensive and static, if it is already there better to avoid removing it
238 CREATE TABLE wikipedia_article (
239     language text NOT NULL,
240     title text NOT NULL,
241     langcount integer,
242     othercount integer,
243     totalcount integer,
244     lat double precision,
245     lon double precision,
246     importance double precision,
247     osm_type character(1),
248     osm_id bigint,
249     wd_page_title text,
250     instance_of text
251 );
252 ALTER TABLE ONLY wikipedia_article ADD CONSTRAINT wikipedia_article_pkey PRIMARY KEY (language, title);
253 CREATE INDEX idx_wikipedia_article_osm_id ON wikipedia_article USING btree (osm_type, osm_id);
254
255 CREATE TABLE wikipedia_redirect (
256     language text,
257     from_title text,
258     to_title text
259 );
260 ALTER TABLE ONLY wikipedia_redirect ADD CONSTRAINT wikipedia_redirect_pkey PRIMARY KEY (language, from_title);
261