source: other-projects/tipple-android/osmosis/script/pgsnapshot_schema_0.6_bbox.sql@ 26899

Last change on this file since 26899 was 26899, checked in by davidb, 11 years ago

Tipple reborn after Chris's Summer of Code 2013

File size: 834 bytes
Line 
1-- Add a postgis GEOMETRY column to the way table for the purpose of indexing the location of the way.
2-- This will contain a bounding box surrounding the extremities of the way.
3SELECT AddGeometryColumn('ways', 'bbox', 4326, 'GEOMETRY', 2);
4
5-- Add an index to the bbox column.
6CREATE INDEX idx_ways_bbox ON ways USING gist (bbox);
7
8-- Cluster table by geographical location.
9CLUSTER ways USING idx_ways_bbox;
10
11-- Create an aggregate function that always returns the first non-NULL item. This is required for bbox queries.
12CREATE OR REPLACE FUNCTION first_agg (anyelement, anyelement)
13RETURNS anyelement AS $$
14 SELECT CASE WHEN $1 IS NULL THEN $2 ELSE $1 END;
15$$ LANGUAGE SQL STABLE;
16
17CREATE AGGREGATE first (
18 sfunc = first_agg,
19 basetype = anyelement,
20 stype = anyelement
21);
Note: See TracBrowser for help on using the repository browser.