mirror of
https://git.osgeo.org/gitea/postgis/postgis
synced 2024-10-26 01:52:37 +00:00
Moved old version-specific sql files under the Attic directory.
git-svn-id: http://svn.osgeo.org/postgis/trunk@601 b70326c6-7e19-0410-871a-916f4a2858ee
This commit is contained in:
parent
e0068515c0
commit
b16f5117aa
|
@ -1,395 +0,0 @@
|
|||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
--
|
||||
-- $Id$
|
||||
--
|
||||
-- PostGIS - Spatial Types for PostgreSQL
|
||||
-- http://postgis.refractions.net
|
||||
-- Copyright 2001-2003 Refractions Research Inc.
|
||||
--
|
||||
-- This is free software; you can redistribute and/or modify it under
|
||||
-- the terms of hte GNU General Public Licence. See the COPYING file.
|
||||
--
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- $Log$
|
||||
-- Revision 1.5 2003/12/30 10:40:21 strk
|
||||
-- For all versions:
|
||||
-- Updated fix_geometry_columns to use a more readable format in queries.
|
||||
--
|
||||
-- For PG >= 73:
|
||||
-- Updated fix_geometry_columns() to consider schema when fixing attrelid and
|
||||
-- varattnum, also changed empty value to 'public' string for records with
|
||||
-- an invalid schema specification.
|
||||
-- Updated DropGeometryColumn to actually issue the
|
||||
-- ALTER TABLE DROP COLUMN query.
|
||||
--
|
||||
-- Revision 1.4 2003/12/23 09:00:12 strk
|
||||
-- AddGeometryColumn, DropGeometryColum moved to version-specific scripts.
|
||||
-- Schema support enabled for version 73 and 74.
|
||||
--
|
||||
-- Revision 1.3 2003/12/18 18:07:06 strk
|
||||
-- Changed fix_geometry_columns() for PG >= 73 so to set f_table_schema to
|
||||
-- the empty string if its value is not a valid pg namespace.
|
||||
--
|
||||
-- Revision 1.2 2003/07/01 18:30:55 pramsey
|
||||
-- Added CVS revision headers.
|
||||
--
|
||||
--
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
|
||||
--
|
||||
-- GiST support functions
|
||||
--
|
||||
|
||||
CREATE FUNCTION ggeometry_consistent(opaque,geometry,int4)
|
||||
RETURNS bool
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION ggeometry_compress(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION ggeometry_penalty(opaque,opaque,opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION ggeometry_picksplit(opaque, opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION ggeometry_union(bytea, opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION ggeometry_same(opaque, opaque, opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION rtree_decompress(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
--
|
||||
-- R-Tree support functions
|
||||
--
|
||||
|
||||
CREATE FUNCTION geometry_union(geometry,geometry)
|
||||
RETURNS geometry
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION geometry_inter(geometry,geometry)
|
||||
RETURNS geometry
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION geometry_size(geometry,opaque)
|
||||
RETURNS float4
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
INSERT INTO pg_opclass (opcname, opcdeftype)
|
||||
SELECT 'gist_geometry_ops', oid
|
||||
FROM pg_type
|
||||
WHERE typname = 'geometry';
|
||||
|
||||
SELECT o.oid AS opoid, o.oprname
|
||||
INTO TABLE rt_ops_tmp
|
||||
FROM pg_operator o, pg_type t
|
||||
WHERE o.oprleft = t.oid AND t.typname = 'geometry';
|
||||
|
||||
-- box_left
|
||||
INSERT INTO pg_amop (amopid, amopclaid, amopopr, amopstrategy)
|
||||
SELECT am.oid, opcl.oid, c.opoid, 1
|
||||
FROM pg_am am, pg_opclass opcl, rt_ops_tmp c
|
||||
WHERE amname = 'gist' AND opcname = 'gist_geometry_ops'
|
||||
AND c.oprname = '<<';
|
||||
|
||||
-- box_overleft
|
||||
INSERT INTO pg_amop (amopid, amopclaid, amopopr, amopstrategy)
|
||||
SELECT am.oid, opcl.oid, c.opoid, 2
|
||||
FROM pg_am am, pg_opclass opcl, rt_ops_tmp c
|
||||
WHERE amname = 'gist' AND opcname = 'gist_geometry_ops'
|
||||
AND c.oprname = '&<';
|
||||
|
||||
-- box_overlap
|
||||
INSERT INTO pg_amop (amopid, amopclaid, amopopr, amopstrategy)
|
||||
SELECT am.oid, opcl.oid, c.opoid, 3
|
||||
FROM pg_am am, pg_opclass opcl, rt_ops_tmp c
|
||||
WHERE amname = 'gist' AND opcname = 'gist_geometry_ops'
|
||||
AND c.oprname = '&&';
|
||||
|
||||
-- box_overright
|
||||
INSERT INTO pg_amop (amopid, amopclaid, amopopr, amopstrategy)
|
||||
SELECT am.oid, opcl.oid, c.opoid, 4
|
||||
FROM pg_am am, pg_opclass opcl, rt_ops_tmp c
|
||||
WHERE amname = 'gist' AND opcname = 'gist_geometry_ops'
|
||||
AND c.oprname = '&>';
|
||||
|
||||
-- box_right
|
||||
INSERT INTO pg_amop (amopid, amopclaid, amopopr, amopstrategy)
|
||||
SELECT am.oid, opcl.oid, c.opoid, 5
|
||||
FROM pg_am am, pg_opclass opcl, rt_ops_tmp c
|
||||
WHERE amname = 'gist' AND opcname = 'gist_geometry_ops'
|
||||
AND c.oprname = '>>';
|
||||
|
||||
-- box_same
|
||||
INSERT INTO pg_amop (amopid, amopclaid, amopopr, amopstrategy)
|
||||
SELECT am.oid, opcl.oid, c.opoid, 6
|
||||
FROM pg_am am, pg_opclass opcl, rt_ops_tmp c
|
||||
WHERE amname = 'gist' AND opcname = 'gist_geometry_ops'
|
||||
AND c.oprname = '~=';
|
||||
|
||||
-- box_contains
|
||||
INSERT INTO pg_amop (amopid, amopclaid, amopopr, amopstrategy)
|
||||
SELECT am.oid, opcl.oid, c.opoid, 7
|
||||
FROM pg_am am, pg_opclass opcl, rt_ops_tmp c
|
||||
WHERE amname = 'gist' AND opcname = 'gist_geometry_ops'
|
||||
AND c.oprname = '~';
|
||||
|
||||
-- box_contained
|
||||
INSERT INTO pg_amop (amopid, amopclaid, amopopr, amopstrategy)
|
||||
SELECT am.oid, opcl.oid, c.opoid, 8
|
||||
FROM pg_am am, pg_opclass opcl, rt_ops_tmp c
|
||||
WHERE amname = 'gist' AND opcname = 'gist_geometry_ops'
|
||||
AND c.oprname = '@';
|
||||
|
||||
DROP TABLE rt_ops_tmp;
|
||||
|
||||
--
|
||||
-- Add the entries to amproc for the support methods.
|
||||
-- Note the amprocnum numbers associated with each are specific!
|
||||
--
|
||||
|
||||
INSERT INTO pg_amproc (amid, amopclaid, amproc, amprocnum)
|
||||
SELECT am.oid, opcl.oid, pro.oid, 1
|
||||
FROM pg_am am, pg_opclass opcl, pg_proc pro
|
||||
WHERE amname = 'gist' AND opcname = 'gist_geometry_ops'
|
||||
AND proname = 'ggeometry_consistent';
|
||||
|
||||
INSERT INTO pg_amproc (amid, amopclaid, amproc, amprocnum)
|
||||
SELECT am.oid, opcl.oid, pro.oid, 2
|
||||
FROM pg_am am, pg_opclass opcl, pg_proc pro
|
||||
WHERE amname = 'gist' AND opcname = 'gist_geometry_ops'
|
||||
AND proname = 'ggeometry_union';
|
||||
|
||||
INSERT INTO pg_amproc (amid, amopclaid, amproc, amprocnum)
|
||||
SELECT am.oid, opcl.oid, pro.oid, 3
|
||||
FROM pg_am am, pg_opclass opcl, pg_proc pro
|
||||
WHERE amname = 'gist' AND opcname = 'gist_geometry_ops'
|
||||
AND proname = 'ggeometry_compress';
|
||||
|
||||
INSERT INTO pg_amproc (amid, amopclaid, amproc, amprocnum)
|
||||
SELECT am.oid, opcl.oid, pro.oid, 4
|
||||
FROM pg_am am, pg_opclass opcl, pg_proc pro
|
||||
WHERE amname = 'gist' AND opcname = 'gist_geometry_ops'
|
||||
AND proname = 'rtree_decompress';
|
||||
|
||||
INSERT INTO pg_amproc (amid, amopclaid, amproc, amprocnum)
|
||||
SELECT am.oid, opcl.oid, pro.oid, 5
|
||||
FROM pg_am am, pg_opclass opcl, pg_proc pro
|
||||
WHERE amname = 'gist' AND opcname = 'gist_geometry_ops'
|
||||
AND proname = 'ggeometry_penalty';
|
||||
|
||||
INSERT INTO pg_amproc (amid, amopclaid, amproc, amprocnum)
|
||||
SELECT am.oid, opcl.oid, pro.oid, 6
|
||||
FROM pg_am am, pg_opclass opcl, pg_proc pro
|
||||
WHERE amname = 'gist' AND opcname = 'gist_geometry_ops'
|
||||
AND proname = 'ggeometry_picksplit';
|
||||
|
||||
INSERT INTO pg_amproc (amid, amopclaid, amproc, amprocnum)
|
||||
SELECT am.oid, opcl.oid, pro.oid, 7
|
||||
FROM pg_am am, pg_opclass opcl, pg_proc pro
|
||||
WHERE amname = 'gist' AND opcname = 'gist_geometry_ops'
|
||||
AND proname = 'ggeometry_same';
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- FIX_GEOMETRY_COLUMNS()
|
||||
|
||||
CREATE FUNCTION fix_geometry_columns() RETURNS text
|
||||
AS
|
||||
'
|
||||
BEGIN
|
||||
UPDATE geometry_columns SET attrelid = ( SELECT c.oid AS attrelid FROM pg_class c, pg_attribute a WHERE c.relname = geometry_columns.f_table_name::name AND a.attrelid = c.oid AND a.attname = geometry_columns.f_geometry_column::name
|
||||
);
|
||||
UPDATE geometry_columns SET varattnum = ( SELECT a.attnum FROM pg_class c, pg_attribute a WHERE c.relname = geometry_columns.f_table_name::name AND a.attrelid = c.oid AND a.attname = geometry_columns.f_geometry_column::name
|
||||
);
|
||||
|
||||
RETURN ''geometry_columns table is now linked to the system tables'';
|
||||
END;
|
||||
'
|
||||
LANGUAGE 'plpgsql' ;
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- ADDGEOMETRYCOLUMN (
|
||||
-- <catalog>, <schema>, <table name>, <column name>,
|
||||
-- <srid>, <type>, <dim> )
|
||||
--
|
||||
-- Type can be one of geometry, GEOMETRYCOLLECTION, POINT, MULTIPOINT, POLYGON,
|
||||
-- MULTIPOLYGON, LINESTRING, or MULTILINESTRING.
|
||||
--
|
||||
-- Types (except geometry) are checked for consistency using a CHECK constraint
|
||||
-- uses SQL ALTER TABLE command to add the geometry column to the table.
|
||||
-- Addes a row to geometry_columns.
|
||||
-- Addes a constraint on the table that all the geometries MUST have the same
|
||||
-- SRID. Checks the coord_dimension to make sure its between 0 and 3.
|
||||
-- Should also check the precision grid (future expansion).
|
||||
-- Calls fix_geometry_columns() at the end.
|
||||
--
|
||||
CREATE FUNCTION AddGeometryColumn(varchar,varchar,varchar,varchar,integer,varchar,integer)
|
||||
RETURNS text
|
||||
AS
|
||||
'
|
||||
DECLARE
|
||||
catalog_name alias for $1;
|
||||
schema_name alias for $2;
|
||||
table_name alias for $3;
|
||||
column_name alias for $4;
|
||||
new_srid alias for $5;
|
||||
new_type alias for $6;
|
||||
new_dim alias for $7;
|
||||
|
||||
BEGIN
|
||||
|
||||
IF ( not ( (new_type =''GEOMETRY'') or
|
||||
(new_type =''GEOMETRYCOLLECTION'') or
|
||||
(new_type =''POINT'') or
|
||||
(new_type =''MULTIPOINT'') or
|
||||
(new_type =''POLYGON'') or
|
||||
(new_type =''MULTIPOLYGON'') or
|
||||
(new_type =''LINESTRING'') or
|
||||
(new_type =''MULTILINESTRING'')) )
|
||||
THEN
|
||||
RAISE EXCEPTION ''Invalid type name - valid ones are:
|
||||
GEOMETRY, GEOMETRYCOLLECTION, POINT,
|
||||
MULTIPOINT, POLYGON, MULTIPOLYGON,
|
||||
LINESTRING, or MULTILINESTRING '';
|
||||
return ''fail'';
|
||||
END IF;
|
||||
|
||||
IF ( (new_dim >3) or (new_dim <0) ) THEN
|
||||
RAISE EXCEPTION ''invalid dimension'';
|
||||
return ''fail'';
|
||||
END IF;
|
||||
|
||||
EXECUTE ''ALTER TABLE '' || quote_ident(table_name) ||
|
||||
'' ADD COLUMN '' || quote_ident(column_name) ||
|
||||
'' geometry '';
|
||||
|
||||
EXECUTE ''INSERT INTO geometry_columns VALUES ('' ||
|
||||
quote_literal('''') || '','' ||
|
||||
quote_literal('''') || '','' ||
|
||||
quote_literal(table_name) || '','' ||
|
||||
quote_literal(column_name) || '','' ||
|
||||
new_dim || '','' || new_srid || '','' ||
|
||||
quote_literal(new_type) || '')'';
|
||||
|
||||
EXECUTE ''select fix_geometry_columns()'';
|
||||
|
||||
EXECUTE ''ALTER TABLE '' || quote_ident(table_name) ||
|
||||
'' ADD CHECK (SRID('' || quote_ident(column_name) ||
|
||||
'') = '' || new_srid || '')'' ;
|
||||
|
||||
IF (not(new_type = ''GEOMETRY'')) THEN
|
||||
EXECUTE ''ALTER TABLE '' || quote_ident(table_name) ||
|
||||
'' ADD CHECK (geometrytype('' ||
|
||||
quote_ident(column_name) || '')='' ||
|
||||
quote_literal(new_type) || '' OR ('' ||
|
||||
quote_ident(column_name) || '') is null)'';
|
||||
END IF;
|
||||
|
||||
return ''Geometry column '' || column_name || '' added to table ''
|
||||
|| table_name || '' WITH a SRID of '' || new_srid ||
|
||||
'' and type '' || new_type;
|
||||
END;
|
||||
' LANGUAGE 'plpgsql' WITH (isstrict);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- ADDGEOMETRYCOLUMN ( <schema>, <table>, <column>, <srid>, <type>, <dim> )
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
CREATE FUNCTION AddGeometryColumn(varchar,varchar,varchar,integer,varchar,integer) RETURNS text AS '
|
||||
DECLARE
|
||||
ret text;
|
||||
BEGIN
|
||||
SELECT AddGeometryColumn('''',$1,$2,$3,$4,$5,$6) into ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
' LANGUAGE 'plpgsql' WITH (isstrict);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- DROPGEOMETRYCOLUMN( <schema name>, <table name>, <column name> )
|
||||
--
|
||||
-- There is no ALTER TABLE DROP COLUMN command in postgresql
|
||||
-- There is no ALTER TABLE DROP CONSTRAINT command in postgresql
|
||||
-- So, we:
|
||||
-- 1. remove the unwanted geom column reference from the
|
||||
-- geometry_columns table
|
||||
-- 2. update the table so that the geometry column is all NULLS
|
||||
-- This is okay since the CHECK srid(geometry) = <srid> is not
|
||||
-- checked if geometry is NULL (the isstrict attribute on srid())
|
||||
-- 3. add another constraint that the geometry column must be NULL
|
||||
-- This, effectively kills the geometry column
|
||||
-- (a) its not in the geometry_column table
|
||||
-- (b) it only has nulls in it
|
||||
-- (c) you cannot add anything to the geom column because it must be NULL
|
||||
--
|
||||
-- This will screw up if you put a NOT NULL constraint on the geometry
|
||||
-- column, so the first thing we must do is remove this constraint (its a
|
||||
-- modification of the pg_attribute system table)
|
||||
--
|
||||
-- We also check to see if the table/column exists in the geometry_columns
|
||||
-- table
|
||||
|
||||
CREATE FUNCTION DropGeometryColumn(varchar,varchar,varchar)
|
||||
RETURNS text
|
||||
AS
|
||||
'
|
||||
DECLARE
|
||||
schema_name alias for $1;
|
||||
table_name alias for $2;
|
||||
column_name alias for $3;
|
||||
myrec RECORD;
|
||||
okay boolean;
|
||||
BEGIN
|
||||
-- first we find out if the column is in the geometry_columns table
|
||||
okay = ''f'';
|
||||
FOR myrec IN SELECT * from geometry_columns where f_table_schema = schema_name and f_table_name = table_name and f_geometry_column = column_name LOOP
|
||||
okay := ''t'';
|
||||
END LOOP;
|
||||
IF (okay <> ''t'') THEN
|
||||
RAISE EXCEPTION ''column not found in geometry_columns table'';
|
||||
return ''f'';
|
||||
END IF;
|
||||
|
||||
-- ensure the geometry column does not have a NOT NULL attribute
|
||||
EXECUTE ''update pg_attribute set attnotnull = false from pg_class where pg_attribute.attrelid = pg_class.oid and pg_class.relname = '' || quote_literal(table_name) ||'' and pg_attribute.attname = '' || quote_literal(column_name);
|
||||
|
||||
-- remove ref from geometry_columns table
|
||||
EXECUTE ''delete from geometry_columns where f_table_schema = '' || quote_literal(database_name) ||
|
||||
'' and f_table_name = '' || quote_literal(table_name) ||
|
||||
'' and f_geometry_column = '' || quote_literal(column_name );
|
||||
|
||||
-- update the given table/column so that it it all NULLS
|
||||
|
||||
EXECUTE ''update "''||table_name||''" set "''||column_name||''"= NULL'';
|
||||
|
||||
-- add = NULL constraint to given table/column
|
||||
|
||||
EXECUTE ''ALTER TABLE "''||table_name||''" ADD CHECK ("''||column_name||''" IS NULL)'';
|
||||
|
||||
RETURN table_name || ''.'' || column_name ||'' effectively removed.'';
|
||||
|
||||
END;
|
||||
'
|
||||
LANGUAGE 'plpgsql' WITH (isstrict);
|
||||
|
||||
|
||||
END TRANSACTION;
|
|
@ -1,165 +0,0 @@
|
|||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
--
|
||||
-- $Id$
|
||||
--
|
||||
-- PostGIS - Spatial Types for PostgreSQL
|
||||
-- http://postgis.refractions.net
|
||||
-- Copyright 2001-2003 Refractions Research Inc.
|
||||
--
|
||||
-- This is free software; you can redistribute and/or modify it under
|
||||
-- the terms of hte GNU General Public Licence. See the COPYING file.
|
||||
--
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- $Log$
|
||||
-- Revision 1.2 2003/07/01 18:30:55 pramsey
|
||||
-- Added CVS revision headers.
|
||||
--
|
||||
--
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
|
||||
-- You might have to define the PL/PgSQL language usually done with the
|
||||
-- changelang script.
|
||||
|
||||
-- Here's some hokey code to test to see if PL/PgSQL is installed
|
||||
-- if it is, you get a message "PL/PgSQL is installed"
|
||||
-- otherwise it will give a big error message.
|
||||
|
||||
(select 'PL/PgSQL is installed.' as message from pg_language where lanname='plpgsql') union (select 'You must install PL/PgSQL before running this SQL file,\nor you will get an error. To install PL/PgSQL run:\n\tcreatelang plpgsql <dbname>'::text as message) order by message limit 1;
|
||||
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- HISTOGRAM2D
|
||||
|
||||
CREATE FUNCTION histogram2d_in(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION histogram2d_out(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE histogram2d (
|
||||
alignment = double,
|
||||
internallength = variable,
|
||||
input = histogram2d_in,
|
||||
output = histogram2d_out,
|
||||
storage = main
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- BOX3D
|
||||
|
||||
CREATE FUNCTION box3d_in(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION box3d_out(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE box3d (
|
||||
alignment = double,
|
||||
internallength = 48,
|
||||
input = box3d_in,
|
||||
output = box3d_out
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- SPHEROID
|
||||
|
||||
CREATE FUNCTION spheroid_in(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@','ellipsoid_in'
|
||||
LANGUAGE 'C' WITH (isstrict,iscachable);
|
||||
|
||||
CREATE FUNCTION spheroid_out(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@','ellipsoid_out'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE spheroid (
|
||||
alignment = double,
|
||||
internallength = 65,
|
||||
input = spheroid_in,
|
||||
output = spheroid_out
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- WKB
|
||||
|
||||
CREATE FUNCTION wkb_in(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@','WKB_in'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION wkb_out(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@','WKB_out'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE wkb (
|
||||
internallength = variable,
|
||||
input = wkb_in,
|
||||
output = wkb_out,
|
||||
storage = extended
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- CHIP
|
||||
|
||||
CREATE FUNCTION chip_in(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@','CHIP_in'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION chip_out(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@','CHIP_out'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE chip (
|
||||
alignment = double,
|
||||
internallength = variable,
|
||||
input = chip_in,
|
||||
output = chip_out,
|
||||
storage = extended
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- GEOMETRY
|
||||
|
||||
CREATE FUNCTION geometry_in(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION geometry_out(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE geometry (
|
||||
alignment = double,
|
||||
internallength = variable,
|
||||
input = geometry_in,
|
||||
output = geometry_out,
|
||||
storage = main
|
||||
);
|
||||
|
||||
--
|
||||
-- GiST Selectivity Function
|
||||
--
|
||||
|
||||
CREATE FUNCTION postgis_gist_sel(oid, oid, int2, opaque, int4)
|
||||
RETURNS float8
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
|
@ -1,510 +0,0 @@
|
|||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
--
|
||||
-- $Id$
|
||||
--
|
||||
-- PostGIS - Spatial Types for PostgreSQL
|
||||
-- http://postgis.refractions.net
|
||||
-- Copyright 2001-2003 Refractions Research Inc.
|
||||
--
|
||||
-- This is free software; you can redistribute and/or modify it under
|
||||
-- the terms of hte GNU General Public Licence. See the COPYING file.
|
||||
--
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- $Log$
|
||||
-- Revision 1.6 2003/12/30 10:40:21 strk
|
||||
-- For all versions:
|
||||
-- Updated fix_geometry_columns to use a more readable format in queries.
|
||||
--
|
||||
-- For PG >= 73:
|
||||
-- Updated fix_geometry_columns() to consider schema when fixing attrelid and
|
||||
-- varattnum, also changed empty value to 'public' string for records with
|
||||
-- an invalid schema specification.
|
||||
-- Updated DropGeometryColumn to actually issue the
|
||||
-- ALTER TABLE DROP COLUMN query.
|
||||
--
|
||||
-- Revision 1.5 2003/12/23 09:00:12 strk
|
||||
-- AddGeometryColumn, DropGeometryColum moved to version-specific scripts.
|
||||
-- Schema support enabled for version 73 and 74.
|
||||
--
|
||||
-- Revision 1.4 2003/12/18 18:07:06 strk
|
||||
-- Changed fix_geometry_columns() for PG >= 73 so to set f_table_schema to
|
||||
-- the empty string if its value is not a valid pg namespace.
|
||||
--
|
||||
-- Revision 1.3 2003/07/01 18:30:55 pramsey
|
||||
-- Added CVS revision headers.
|
||||
--
|
||||
--
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- UPDATE_GEOMETRY_STATS()
|
||||
|
||||
CREATE FUNCTION update_geometry_stats() RETURNS text
|
||||
AS
|
||||
'
|
||||
BEGIN
|
||||
EXECUTE ''update geometry_columns set attrelid = (select pg_class.oid AS attrelid from pg_class,pg_attribute where relname =geometry_columns.f_table_name::name and pg_attribute.attrelid = pg_class.oid and pg_attribute.attname = geometry_columns.f_GEOMETRY_column::name), varattnum = (select pg_attribute.attnum from pg_class,pg_attribute where relname =geometry_columns.f_table_name::name and pg_attribute.attrelid = pg_class.oid and pg_attribute.attname = geometry_columns.f_GEOMETRY_column::name)'';
|
||||
execute ''update geometry_columns set stats = (build_histogram2d( create_histogram2d(find_extent(f_table_name,f_GEOMETRY_column),40 ),f_table_name::text, f_GEOMETRY_column::text)) '';
|
||||
return ''done'';
|
||||
END;
|
||||
'
|
||||
LANGUAGE 'plpgsql' ;
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- UPDATE_GEOMETRY_STATS( <table>, <column> )
|
||||
|
||||
CREATE FUNCTION update_geometry_stats(varchar,varchar) RETURNS text
|
||||
AS
|
||||
'
|
||||
DECLARE
|
||||
tablename aliAS for $1;
|
||||
columnname aliAS for $2;
|
||||
|
||||
BEGIN
|
||||
EXECUTE ''update geometry_columns set attrelid = (select pg_class.oid AS attrelid from pg_class,pg_attribute where relname =geometry_columns.f_table_name::name and pg_attribute.attrelid = pg_class.oid and pg_attribute.attname = geometry_columns.f_GEOMETRY_column::name), varattnum = (select pg_attribute.attnum from pg_class,pg_attribute where relname =geometry_columns.f_table_name::name and pg_attribute.attrelid = pg_class.oid and pg_attribute.attname = geometry_columns.f_GEOMETRY_column::name)'';
|
||||
execute ''update geometry_columns set stats = (build_histogram2d( create_histogram2d(find_extent(''|| quote_literal(tablename) || '',''||quote_literal(columnname) ||''),40 ),''|| quote_literal(tablename) || ''::text,''||quote_literal(columnname) ||''::text )) WHERE f_table_name=''|| quote_literal(tablename) || ''and f_GEOMETRY_column=''||quote_literal(columnname) ;
|
||||
return ''done'';
|
||||
END;
|
||||
'
|
||||
LANGUAGE 'plpgsql' ;
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- CREATE_HISTOGRAM2D( <box>, <size> )
|
||||
--
|
||||
-- Returns a histgram with 0s in all the boxes.
|
||||
|
||||
CREATE FUNCTION create_histogram2d(box3d,int)
|
||||
RETURNS histogram2d
|
||||
AS '@MODULE_FILENAME@','create_histogram2d'
|
||||
LANGUAGE 'C' with (isstrict);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- BUILD_HISTOGRAM2D( <histogram2d>, <tablename>, <columnname> )
|
||||
--
|
||||
|
||||
CREATE FUNCTION build_histogram2d (HISTOGRAM2D,text,text)
|
||||
RETURNS histogram2d
|
||||
AS '@MODULE_FILENAME@','build_histogram2d'
|
||||
LANGUAGE 'C' with (isstrict);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- EXPLODE_HISTOGRAM2D( <histogram2d>, <tablename> )
|
||||
--
|
||||
|
||||
CREATE FUNCTION explode_histogram2d (HISTOGRAM2D,text)
|
||||
RETURNS histogram2d
|
||||
AS '@MODULE_FILENAME@','explode_histogram2d'
|
||||
LANGUAGE 'C' with (isstrict);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- ESTIMATE_HISTOGRAM2D( <histogram2d>, <box> )
|
||||
--
|
||||
|
||||
CREATE FUNCTION estimate_histogram2d(HISTOGRAM2D,box)
|
||||
RETURNS float8
|
||||
AS '@MODULE_FILENAME@','estimate_histogram2d'
|
||||
LANGUAGE 'C' with (isstrict);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- POSTGISCOSTESTIMATE()
|
||||
--
|
||||
|
||||
CREATE FUNCTION postgisgistcostestimate(opaque,opaque,opaque,opaque,opaque,opaque,opaque,opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@','postgisgistcostestimate'
|
||||
LANGUAGE 'C' with (isstrict);
|
||||
|
||||
--
|
||||
-- 7.2 GiST support functions
|
||||
--
|
||||
|
||||
CREATE FUNCTION ggeometry_consistent(opaque,geometry,int4)
|
||||
RETURNS bool
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE'C';
|
||||
|
||||
CREATE FUNCTION ggeometry_compress(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE'C';
|
||||
|
||||
CREATE FUNCTION gbox_penalty(opaque,opaque,opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE'C';
|
||||
|
||||
CREATE FUNCTION gbox_picksplit(opaque, opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE'C';
|
||||
|
||||
CREATE FUNCTION gbox_union(bytea, opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE'C';
|
||||
|
||||
CREATE FUNCTION gbox_same(box, box, opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE'C';
|
||||
|
||||
CREATE FUNCTION rtree_decompress(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE'C';
|
||||
|
||||
--
|
||||
-- 7.2 RTREE support functions
|
||||
--
|
||||
|
||||
CREATE FUNCTION geometry_union(geometry,geometry)
|
||||
RETURNS geometry
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE'C';
|
||||
|
||||
CREATE FUNCTION geometry_inter(geometry,geometry)
|
||||
RETURNS geometry
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE'C';
|
||||
|
||||
CREATE FUNCTION geometry_size(geometry,opaque)
|
||||
RETURNS float4
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE'C';
|
||||
|
||||
--
|
||||
-- Create opclass index binding entries.
|
||||
--
|
||||
|
||||
INSERT INTO pg_opclass (opcamid, opcname, opcintype, opcdefault, opckeytype)
|
||||
VALUES (
|
||||
(SELECT oid FROM pg_am WHERE amname = 'gist'),
|
||||
'gist_geometry_ops',
|
||||
(SELECT oid FROM pg_type WHERE typname = 'geometry'),
|
||||
true,
|
||||
(SELECT oid FROM pg_type WHERE typname = 'box'));
|
||||
|
||||
-- drop table rt_ops_tmp;
|
||||
|
||||
SELECT o.oid AS opoid, o.oprname
|
||||
INTO TABLE rt_ops_tmp
|
||||
FROM pg_operator o, pg_type t
|
||||
WHERE o.oprleft = t.oid
|
||||
AND t.typname = 'geometry';
|
||||
|
||||
-- poly_left
|
||||
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
|
||||
SELECT opcl.oid, 1, true, c.opoid
|
||||
FROM pg_opclass opcl, rt_ops_tmp c
|
||||
WHERE
|
||||
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
|
||||
and opcname = 'gist_geometry_ops'
|
||||
and c.oprname = '<<';
|
||||
|
||||
-- poly_overleft
|
||||
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
|
||||
SELECT opcl.oid, 2, true, c.opoid
|
||||
FROM pg_opclass opcl, rt_ops_tmp c
|
||||
WHERE
|
||||
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
|
||||
and opcname = 'gist_geometry_ops'
|
||||
and c.oprname = '&<';
|
||||
|
||||
-- poly_overlap
|
||||
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
|
||||
SELECT opcl.oid, 3, true, c.opoid
|
||||
FROM pg_opclass opcl, rt_ops_tmp c
|
||||
WHERE
|
||||
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
|
||||
and opcname = 'gist_geometry_ops'
|
||||
and c.oprname = '&&';
|
||||
|
||||
-- poly_overright
|
||||
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
|
||||
SELECT opcl.oid, 4, true, c.opoid
|
||||
FROM pg_opclass opcl, rt_ops_tmp c
|
||||
WHERE
|
||||
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
|
||||
and opcname = 'gist_geometry_ops'
|
||||
and c.oprname = '&>';
|
||||
|
||||
-- poly_right
|
||||
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
|
||||
SELECT opcl.oid, 5, true, c.opoid
|
||||
FROM pg_opclass opcl, rt_ops_tmp c
|
||||
WHERE
|
||||
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
|
||||
and opcname = 'gist_geometry_ops'
|
||||
and c.oprname = '>>';
|
||||
|
||||
-- poly_same
|
||||
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
|
||||
SELECT opcl.oid, 6, true, c.opoid
|
||||
FROM pg_opclass opcl, rt_ops_tmp c
|
||||
WHERE
|
||||
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
|
||||
and opcname = 'gist_geometry_ops'
|
||||
and c.oprname = '~=';
|
||||
|
||||
-- poly_contains
|
||||
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
|
||||
SELECT opcl.oid, 7, true, c.opoid
|
||||
FROM pg_opclass opcl, rt_ops_tmp c
|
||||
WHERE
|
||||
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
|
||||
and opcname = 'gist_geometry_ops'
|
||||
and c.oprname = '~';
|
||||
|
||||
-- poly_contained
|
||||
INSERT INTO pg_amop (amopclaid, amopstrategy, amopreqcheck, amopopr)
|
||||
SELECT opcl.oid, 8, true, c.opoid
|
||||
FROM pg_opclass opcl, rt_ops_tmp c
|
||||
WHERE
|
||||
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
|
||||
and opcname = 'gist_geometry_ops'
|
||||
and c.oprname = '@';
|
||||
|
||||
DROP TABLE rt_ops_tmp;
|
||||
|
||||
-- add the entries to amproc for the support methods
|
||||
-- note the amprocnum numbers associated with each are specific!
|
||||
INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
|
||||
SELECT opcl.oid, 1, pro.oid
|
||||
FROM pg_opclass opcl, pg_proc pro
|
||||
WHERE
|
||||
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
|
||||
and opcname = 'gist_geometry_ops'
|
||||
and proname = 'ggeometry_consistent';
|
||||
|
||||
INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
|
||||
SELECT opcl.oid, 2, pro.oid
|
||||
FROM pg_opclass opcl, pg_proc pro
|
||||
WHERE
|
||||
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
|
||||
and opcname = 'gist_geometry_ops'
|
||||
and proname = 'gbox_union';
|
||||
|
||||
INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
|
||||
SELECT opcl.oid, 3, pro.oid
|
||||
FROM pg_opclass opcl, pg_proc pro
|
||||
WHERE
|
||||
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
|
||||
and opcname = 'gist_geometry_ops'
|
||||
and proname = 'ggeometry_compress';
|
||||
|
||||
INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
|
||||
SELECT opcl.oid, 4, pro.oid
|
||||
FROM pg_opclass opcl, pg_proc pro
|
||||
WHERE
|
||||
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
|
||||
and opcname = 'gist_geometry_ops'
|
||||
and proname = 'rtree_decompress';
|
||||
|
||||
INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
|
||||
SELECT opcl.oid, 5, pro.oid
|
||||
FROM pg_opclass opcl, pg_proc pro
|
||||
WHERE
|
||||
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
|
||||
and opcname = 'gist_geometry_ops'
|
||||
and proname = 'gbox_penalty';
|
||||
|
||||
INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
|
||||
SELECT opcl.oid, 6, pro.oid
|
||||
FROM pg_opclass opcl, pg_proc pro
|
||||
WHERE
|
||||
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
|
||||
and opcname = 'gist_geometry_ops'
|
||||
and proname = 'gbox_picksplit';
|
||||
|
||||
INSERT INTO pg_amproc (amopclaid, amprocnum, amproc)
|
||||
SELECT opcl.oid, 7, pro.oid
|
||||
FROM pg_opclass opcl, pg_proc pro
|
||||
WHERE
|
||||
opcamid = (SELECT oid FROM pg_am WHERE amname = 'gist')
|
||||
and opcname = 'gist_geometry_ops'
|
||||
and proname = 'gbox_same';
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- FIX_GEOMETRY_COLUMNS()
|
||||
|
||||
CREATE FUNCTION fix_geometry_columns() RETURNS text
|
||||
AS
|
||||
'
|
||||
BEGIN
|
||||
|
||||
UPDATE geometry_columns SET attrelid = ( SELECT c.oid AS attrelid FROM pg_class c, pg_attribute a WHERE c.relname = geometry_columns.f_table_name::name AND a.attrelid = c.oid AND a.attname = geometry_columns.f_geometry_column::name
|
||||
);
|
||||
UPDATE geometry_columns SET varattnum = ( SELECT a.attnum FROM pg_class c, pg_attribute a WHERE c.relname = geometry_columns.f_table_name::name AND a.attrelid = c.oid AND a.attname = geometry_columns.f_geometry_column::name
|
||||
);
|
||||
|
||||
RETURN ''geometry_columns table is now linked to the system tables'';
|
||||
|
||||
END;
|
||||
'
|
||||
LANGUAGE 'plpgsql' ;
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- ADDGEOMETRYCOLUMN (
|
||||
-- <catalog>, <schema>, <table name>, <column name>,
|
||||
-- <srid>, <type>, <dim> )
|
||||
--
|
||||
-- Type can be one of geometry, GEOMETRYCOLLECTION, POINT, MULTIPOINT, POLYGON,
|
||||
-- MULTIPOLYGON, LINESTRING, or MULTILINESTRING.
|
||||
--
|
||||
-- Types (except geometry) are checked for consistency using a CHECK constraint
|
||||
-- uses SQL ALTER TABLE command to add the geometry column to the table.
|
||||
-- Addes a row to geometry_columns.
|
||||
-- Addes a constraint on the table that all the geometries MUST have the same
|
||||
-- SRID. Checks the coord_dimension to make sure its between 0 and 3.
|
||||
-- Should also check the precision grid (future expansion).
|
||||
-- Calls fix_geometry_columns() at the end.
|
||||
--
|
||||
CREATE FUNCTION AddGeometryColumn(varchar,varchar,varchar,varchar,integer,varchar,integer)
|
||||
RETURNS text
|
||||
AS
|
||||
'
|
||||
DECLARE
|
||||
catalog_name alias for $1;
|
||||
schema_name alias for $2;
|
||||
table_name alias for $3;
|
||||
column_name alias for $4;
|
||||
new_srid alias for $5;
|
||||
new_type alias for $6;
|
||||
new_dim alias for $7;
|
||||
|
||||
BEGIN
|
||||
|
||||
IF ( not ( (new_type =''GEOMETRY'') or
|
||||
(new_type =''GEOMETRYCOLLECTION'') or
|
||||
(new_type =''POINT'') or
|
||||
(new_type =''MULTIPOINT'') or
|
||||
(new_type =''POLYGON'') or
|
||||
(new_type =''MULTIPOLYGON'') or
|
||||
(new_type =''LINESTRING'') or
|
||||
(new_type =''MULTILINESTRING'')) )
|
||||
THEN
|
||||
RAISE EXCEPTION ''Invalid type name - valid ones are:
|
||||
GEOMETRY, GEOMETRYCOLLECTION, POINT,
|
||||
MULTIPOINT, POLYGON, MULTIPOLYGON,
|
||||
LINESTRING, or MULTILINESTRING '';
|
||||
return ''fail'';
|
||||
END IF;
|
||||
|
||||
IF ( (new_dim >3) or (new_dim <0) ) THEN
|
||||
RAISE EXCEPTION ''invalid dimension'';
|
||||
return ''fail'';
|
||||
END IF;
|
||||
|
||||
EXECUTE ''ALTER TABLE '' || quote_ident(table_name) ||
|
||||
'' ADD COLUMN '' || quote_ident(column_name) ||
|
||||
'' geometry '';
|
||||
|
||||
EXECUTE ''INSERT INTO geometry_columns VALUES ('' ||
|
||||
quote_literal('''') || '','' ||
|
||||
quote_literal('''') || '','' ||
|
||||
quote_literal(table_name) || '','' ||
|
||||
quote_literal(column_name) || '','' ||
|
||||
new_dim || '','' || new_srid || '','' ||
|
||||
quote_literal(new_type) || '')'';
|
||||
|
||||
EXECUTE ''select fix_geometry_columns()'';
|
||||
|
||||
EXECUTE ''ALTER TABLE '' || quote_ident(table_name) ||
|
||||
'' ADD CHECK (SRID('' || quote_ident(column_name) ||
|
||||
'') = '' || new_srid || '')'' ;
|
||||
|
||||
IF (not(new_type = ''GEOMETRY'')) THEN
|
||||
EXECUTE ''ALTER TABLE '' || quote_ident(table_name) ||
|
||||
'' ADD CHECK (geometrytype('' ||
|
||||
quote_ident(column_name) || '')='' ||
|
||||
quote_literal(new_type) || '' OR ('' ||
|
||||
quote_ident(column_name) || '') is null)'';
|
||||
END IF;
|
||||
|
||||
return ''Geometry column '' || column_name || '' added to table ''
|
||||
|| table_name || '' WITH a SRID of '' || new_srid ||
|
||||
'' and type '' || new_type;
|
||||
END;
|
||||
' LANGUAGE 'plpgsql' WITH (isstrict);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- ADDGEOMETRYCOLUMN ( <schema>, <table>, <column>, <srid>, <type>, <dim> )
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
CREATE FUNCTION AddGeometryColumn(varchar,varchar,varchar,integer,varchar,integer) RETURNS text AS '
|
||||
DECLARE
|
||||
ret text;
|
||||
BEGIN
|
||||
SELECT AddGeometryColumn('''',$1,$2,$3,$4,$5,$6) into ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
' LANGUAGE 'plpgsql' WITH (isstrict);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- DROPGEOMETRYCOLUMN( <schema name>, <table name>, <column name> )
|
||||
--
|
||||
-- There is no ALTER TABLE DROP COLUMN command in postgresql
|
||||
-- There is no ALTER TABLE DROP CONSTRAINT command in postgresql
|
||||
-- So, we:
|
||||
-- 1. remove the unwanted geom column reference from the
|
||||
-- geometry_columns table
|
||||
-- 2. update the table so that the geometry column is all NULLS
|
||||
-- This is okay since the CHECK srid(geometry) = <srid> is not
|
||||
-- checked if geometry is NULL (the isstrict attribute on srid())
|
||||
-- 3. add another constraint that the geometry column must be NULL
|
||||
-- This, effectively kills the geometry column
|
||||
-- (a) its not in the geometry_column table
|
||||
-- (b) it only has nulls in it
|
||||
-- (c) you cannot add anything to the geom column because it must be NULL
|
||||
--
|
||||
-- This will screw up if you put a NOT NULL constraint on the geometry
|
||||
-- column, so the first thing we must do is remove this constraint (its a
|
||||
-- modification of the pg_attribute system table)
|
||||
--
|
||||
-- We also check to see if the table/column exists in the geometry_columns
|
||||
-- table
|
||||
|
||||
CREATE FUNCTION DropGeometryColumn(varchar,varchar,varchar)
|
||||
RETURNS text
|
||||
AS
|
||||
'
|
||||
DECLARE
|
||||
schema_name alias for $1;
|
||||
table_name alias for $2;
|
||||
column_name alias for $3;
|
||||
myrec RECORD;
|
||||
okay boolean;
|
||||
BEGIN
|
||||
-- first we find out if the column is in the geometry_columns table
|
||||
okay = ''f'';
|
||||
FOR myrec IN SELECT * from geometry_columns where f_table_schema = schema_name and f_table_name = table_name and f_geometry_column = column_name LOOP
|
||||
okay := ''t'';
|
||||
END LOOP;
|
||||
IF (okay <> ''t'') THEN
|
||||
RAISE EXCEPTION ''column not found in geometry_columns table'';
|
||||
return ''f'';
|
||||
END IF;
|
||||
|
||||
-- ensure the geometry column does not have a NOT NULL attribute
|
||||
EXECUTE ''update pg_attribute set attnotnull = false from pg_class where pg_attribute.attrelid = pg_class.oid and pg_class.relname = '' || quote_literal(table_name) ||'' and pg_attribute.attname = '' || quote_literal(column_name);
|
||||
|
||||
-- remove ref from geometry_columns table
|
||||
EXECUTE ''delete from geometry_columns where f_table_schema = '' || quote_literal(database_name) ||
|
||||
'' and f_table_name = '' || quote_literal(table_name) ||
|
||||
'' and f_geometry_column = '' || quote_literal(column_name );
|
||||
|
||||
-- update the given table/column so that it it all NULLS
|
||||
|
||||
EXECUTE ''update "''||table_name||''" set "''||column_name||''"= NULL'';
|
||||
|
||||
-- add = NULL constraint to given table/column
|
||||
|
||||
EXECUTE ''ALTER TABLE "''||table_name||''" ADD CHECK ("''||column_name||''" IS NULL)'';
|
||||
|
||||
RETURN table_name || ''.'' || column_name ||'' effectively removed.'';
|
||||
|
||||
END;
|
||||
'
|
||||
LANGUAGE 'plpgsql' WITH (isstrict);
|
||||
|
||||
END TRANSACTION;
|
|
@ -1,163 +0,0 @@
|
|||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
--
|
||||
-- $Id$
|
||||
--
|
||||
-- PostGIS - Spatial Types for PostgreSQL
|
||||
-- http://postgis.refractions.net
|
||||
-- Copyright 2001-2003 Refractions Research Inc.
|
||||
--
|
||||
-- This is free software; you can redistribute and/or modify it under
|
||||
-- the terms of hte GNU General Public Licence. See the COPYING file.
|
||||
--
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- $Log$
|
||||
-- Revision 1.2 2003/07/01 18:30:55 pramsey
|
||||
-- Added CVS revision headers.
|
||||
--
|
||||
--
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
-- You might have to define the PL/PgSQL language usually done with the
|
||||
-- changelang script.
|
||||
|
||||
-- Here's some hokey code to test to see if PL/PgSQL is installed
|
||||
-- if it is, you get a message "PL/PgSQL is installed"
|
||||
-- otherwise it will give a big error message.
|
||||
|
||||
(select 'PL/PgSQL is installed.' as message from pg_language where lanname='plpgsql') union (select 'You must install PL/PgSQL before running this SQL file,\nor you will get an error. To install PL/PgSQL run:\n\tcreatelang plpgsql <dbname>'::text as message) order by message limit 1;
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- HISTOGRAM2D
|
||||
|
||||
CREATE FUNCTION histogram2d_in(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION histogram2d_out(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE histogram2d (
|
||||
alignment = double,
|
||||
internallength = variable,
|
||||
input = histogram2d_in,
|
||||
output = histogram2d_out,
|
||||
storage = main
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- BOX3D
|
||||
|
||||
CREATE FUNCTION box3d_in(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION box3d_out(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE box3d (
|
||||
alignment = double,
|
||||
internallength = 48,
|
||||
input = box3d_in,
|
||||
output = box3d_out
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- SPHEROID
|
||||
|
||||
CREATE FUNCTION spheroid_in(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@','ellipsoid_in'
|
||||
LANGUAGE 'C' WITH (isstrict,iscachable);
|
||||
|
||||
CREATE FUNCTION spheroid_out(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@','ellipsoid_out'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE spheroid (
|
||||
alignment = double,
|
||||
internallength = 65,
|
||||
input = spheroid_in,
|
||||
output = spheroid_out
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- WKB
|
||||
|
||||
CREATE FUNCTION wkb_in(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@','WKB_in'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION wkb_out(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@','WKB_out'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE wkb (
|
||||
internallength = variable,
|
||||
input = wkb_in,
|
||||
output = wkb_out,
|
||||
storage = extended
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- CHIP
|
||||
|
||||
CREATE FUNCTION chip_in(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@','CHIP_in'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION chip_out(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@','CHIP_out'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE chip (
|
||||
alignment = double,
|
||||
internallength = variable,
|
||||
input = chip_in,
|
||||
output = chip_out,
|
||||
storage = extended
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- GEOMETRY
|
||||
|
||||
CREATE FUNCTION geometry_in(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION geometry_out(opaque)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE geometry (
|
||||
alignment = double,
|
||||
internallength = variable,
|
||||
input = geometry_in,
|
||||
output = geometry_out,
|
||||
storage = main
|
||||
);
|
||||
|
||||
--
|
||||
-- GiST Selectivity Function
|
||||
--
|
||||
|
||||
CREATE FUNCTION postgis_gist_sel(opaque, oid, opaque, int4)
|
||||
RETURNS float8
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE'C';
|
||||
|
|
@ -1,453 +0,0 @@
|
|||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
--
|
||||
-- $Id$
|
||||
--
|
||||
-- PostGIS - Spatial Types for PostgreSQL
|
||||
-- http://postgis.refractions.net
|
||||
-- Copyright 2001-2003 Refractions Research Inc.
|
||||
--
|
||||
-- This is free software; you can redistribute and/or modify it under
|
||||
-- the terms of hte GNU General Public Licence. See the COPYING file.
|
||||
--
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- $Log$
|
||||
-- Revision 1.9 2004/01/20 20:14:17 strk
|
||||
-- cleaner comments for DropGeometryColumn
|
||||
--
|
||||
-- Revision 1.8 2003/12/30 10:40:21 strk
|
||||
-- For all versions:
|
||||
-- Updated fix_geometry_columns to use a more readable format in queries.
|
||||
--
|
||||
-- For PG >= 73:
|
||||
-- Updated fix_geometry_columns() to consider schema when fixing attrelid and
|
||||
-- varattnum, also changed empty value to 'public' string for records with
|
||||
-- an invalid schema specification.
|
||||
-- Updated DropGeometryColumn to actually issue the
|
||||
-- ALTER TABLE DROP COLUMN query.
|
||||
--
|
||||
-- Revision 1.7 2003/12/23 09:00:12 strk
|
||||
-- AddGeometryColumn, DropGeometryColum moved to version-specific scripts.
|
||||
-- Schema support enabled for version 73 and 74.
|
||||
--
|
||||
-- Revision 1.6 2003/12/18 18:07:06 strk
|
||||
-- Changed fix_geometry_columns() for PG >= 73 so to set f_table_schema to
|
||||
-- the empty string if its value is not a valid pg namespace.
|
||||
--
|
||||
-- Revision 1.5 2003/11/28 11:25:31 strk
|
||||
-- Added explicit geometry as text cast
|
||||
--
|
||||
-- Revision 1.4 2003/07/01 18:30:55 pramsey
|
||||
-- Added CVS revision headers.
|
||||
--
|
||||
--
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
|
||||
--
|
||||
-- 7.3 explicit casting definitions
|
||||
--
|
||||
|
||||
CREATE CAST ( chip AS geometry ) WITH FUNCTION geometry(chip) AS IMPLICIT;
|
||||
CREATE CAST ( geometry AS box3d ) WITH FUNCTION box3d(geometry) AS IMPLICIT;
|
||||
CREATE CAST ( geometry AS box ) WITH FUNCTION box(geometry) AS IMPLICIT;
|
||||
CREATE CAST ( box3d AS geometry ) WITH FUNCTION geometry(box3d) AS IMPLICIT;
|
||||
CREATE CAST ( text AS geometry) WITH FUNCTION geometry(text) AS IMPLICIT;
|
||||
CREATE CAST ( wkb AS bytea ) WITH FUNCTION bytea(wkb) AS IMPLICIT;
|
||||
CREATE CAST ( box3d AS box ) WITH FUNCTION box3dtobox(box3d);
|
||||
CREATE CAST ( geometry AS text ) WITH FUNCTION astext(geometry);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- UPDATE_GEOMETRY_STATS()
|
||||
|
||||
CREATE FUNCTION update_geometry_stats()
|
||||
RETURNS text
|
||||
AS
|
||||
'
|
||||
BEGIN
|
||||
EXECUTE ''update geometry_columns set attrelid = (select pg_class.oid AS attrelid from pg_class,pg_attribute where relname =geometry_columns.f_table_name::name and pg_attribute.attrelid = pg_class.oid and pg_attribute.attname = geometry_columns.f_geometry_column::name), varattnum = (select pg_attribute.attnum from pg_class,pg_attribute where relname =geometry_columns.f_table_name::name and pg_attribute.attrelid = pg_class.oid and pg_attribute.attname = geometry_columns.f_geometry_column::name)'';
|
||||
execute ''update geometry_columns set stats = (build_histogram2d( create_histogram2d(find_extent(f_table_name,f_geometry_column),40 ),f_table_name::text, f_geometry_column::text)) '';
|
||||
return ''done'';
|
||||
END;
|
||||
'
|
||||
LANGUAGE 'plpgsql' ;
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- UPDATE_GEOMETRY_STATS( <table>, <column> )
|
||||
|
||||
CREATE FUNCTION update_geometry_stats(varchar,varchar)
|
||||
RETURNS text
|
||||
AS
|
||||
'
|
||||
DECLARE
|
||||
tablename aliAS for $1;
|
||||
columnname aliAS for $2;
|
||||
|
||||
BEGIN
|
||||
EXECUTE ''update geometry_columns set attrelid = (select pg_class.oid AS attrelid from pg_class,pg_attribute where relname =geometry_columns.f_table_name::name and pg_attribute.attrelid = pg_class.oid and pg_attribute.attname = geometry_columns.f_geometry_column::name), varattnum = (select pg_attribute.attnum from pg_class,pg_attribute where relname =geometry_columns.f_table_name::name and pg_attribute.attrelid = pg_class.oid and pg_attribute.attname = geometry_columns.f_geometry_column::name)'';
|
||||
execute ''update geometry_columns set stats = (build_histogram2d( create_histogram2d(find_extent(''|| quote_literal(tablename) || '',''||quote_literal(columnname) ||''),40 ),''|| quote_literal(tablename) || ''::text,''||quote_literal(columnname) ||''::text )) WHERE f_table_name=''|| quote_literal(tablename) || ''and f_geometry_column=''||quote_literal(columnname) ;
|
||||
return ''done'';
|
||||
END;
|
||||
'
|
||||
LANGUAGE 'plpgsql' ;
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- CREATE_HISTOGRAM2D( <box>, <size> )
|
||||
--
|
||||
-- Returns a histgram with 0s in all the boxes.
|
||||
|
||||
CREATE FUNCTION create_histogram2d(box3d,int)
|
||||
RETURNS histogram2d
|
||||
AS '@MODULE_FILENAME@','create_histogram2d'
|
||||
LANGUAGE 'C' with (isstrict);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- BUILD_HISTOGRAM2D( <histogram2d>, <tablename>, <columnname> )
|
||||
--
|
||||
|
||||
CREATE FUNCTION build_histogram2d (histogram2d, text, text)
|
||||
RETURNS histogram2d
|
||||
AS '@MODULE_FILENAME@','build_histogram2d'
|
||||
LANGUAGE 'C' with (isstrict);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- EXPLODE_HISTOGRAM2D( <histogram2d>, <tablename> )
|
||||
--
|
||||
|
||||
CREATE FUNCTION explode_histogram2d (histogram2d, text)
|
||||
RETURNS histogram2d
|
||||
AS '@MODULE_FILENAME@','explode_histogram2d'
|
||||
LANGUAGE 'C' with (isstrict);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- ESTIMATE_HISTOGRAM2D( <histogram2d>, <box> )
|
||||
--
|
||||
|
||||
CREATE FUNCTION estimate_histogram2d(histogram2d,box)
|
||||
RETURNS float8
|
||||
AS '@MODULE_FILENAME@','estimate_histogram2d'
|
||||
LANGUAGE 'C' with (isstrict);
|
||||
|
||||
CREATE FUNCTION postgisgistcostestimate(internal,internal,internal,internal,internal,internal,internal,internal)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@','postgisgistcostestimate'
|
||||
LANGUAGE 'C' with (isstrict);
|
||||
|
||||
--
|
||||
-- 7.2 GiST support functions
|
||||
--
|
||||
|
||||
CREATE FUNCTION ggeometry_consistent(internal,geometry,int4)
|
||||
RETURNS bool
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION ggeometry_compress(internal)
|
||||
RETURNS internal
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION gbox_penalty(internal,internal,internal)
|
||||
RETURNS internal
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION gbox_picksplit(internal, internal)
|
||||
RETURNS internal
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION gbox_union(bytea, internal)
|
||||
RETURNS internal
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION gbox_same(box, box, internal)
|
||||
RETURNS internal
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION rtree_decompress(internal)
|
||||
RETURNS internal
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
--
|
||||
-- 7.2 RTREE support functions
|
||||
--
|
||||
|
||||
CREATE FUNCTION geometry_union(geometry,geometry)
|
||||
RETURNS geometry
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION geometry_inter(geometry,geometry)
|
||||
RETURNS geometry
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION geometry_size(geometry,internal)
|
||||
RETURNS float4
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
--
|
||||
-- Create opclass index bindings
|
||||
--
|
||||
|
||||
CREATE OPERATOR CLASS gist_geometry_ops
|
||||
DEFAULT FOR TYPE geometry USING gist AS
|
||||
OPERATOR 1 << ,
|
||||
OPERATOR 2 &< ,
|
||||
OPERATOR 3 && ,
|
||||
OPERATOR 4 &> ,
|
||||
OPERATOR 5 >> ,
|
||||
OPERATOR 6 ~= ,
|
||||
OPERATOR 7 ~ ,
|
||||
OPERATOR 8 @ ,
|
||||
FUNCTION 1 ggeometry_consistent (internal, geometry, int4),
|
||||
FUNCTION 2 gbox_union (bytea, internal),
|
||||
FUNCTION 3 ggeometry_compress (internal),
|
||||
FUNCTION 4 rtree_decompress (internal),
|
||||
FUNCTION 5 gbox_penalty (internal, internal, internal),
|
||||
FUNCTION 6 gbox_picksplit (internal, internal),
|
||||
FUNCTION 7 gbox_same (box, box, internal);
|
||||
|
||||
UPDATE pg_opclass
|
||||
SET opckeytype = (select oid from pg_type where typname = 'box')
|
||||
WHERE opcname = 'gist_geometry_ops';
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- FIX_GEOMETRY_COLUMNS()
|
||||
--
|
||||
-- Since 7.3 schema support has been added.
|
||||
-- Previous postgis versions used to put the database name in
|
||||
-- the schema column. This needs to be fixed, so we set to the
|
||||
-- empty string any schema value not existing in pg_namespace
|
||||
--
|
||||
|
||||
CREATE FUNCTION fix_geometry_columns() RETURNS text
|
||||
AS
|
||||
'
|
||||
BEGIN
|
||||
-- it would be better to find the correct schema name
|
||||
UPDATE geometry_columns SET f_table_schema = ''public''
|
||||
WHERE f_table_schema is NULL or f_table_schema NOT IN
|
||||
( SELECT nspname::varchar FROM pg_namespace );
|
||||
|
||||
UPDATE geometry_columns SET attrelid = (
|
||||
SELECT c.oid
|
||||
FROM pg_class c, pg_attribute a, pg_namespace n
|
||||
WHERE c.relname = geometry_columns.f_table_name::name
|
||||
AND a.attrelid = c.oid AND c.relnamespace = n.oid
|
||||
AND a.attname = geometry_columns.f_geometry_column::name
|
||||
AND n.nspname = geometry_columns.f_table_schema::name
|
||||
);
|
||||
|
||||
UPDATE geometry_columns SET varattnum = (
|
||||
SELECT a.attnum
|
||||
FROM pg_class c, pg_attribute a, pg_namespace n
|
||||
WHERE n.nspname = geometry_columns.f_table_schema::name
|
||||
AND c.relname = geometry_columns.f_table_name::name
|
||||
AND a.attname = geometry_columns.f_geometry_column::name
|
||||
AND a.attrelid = c.oid AND c.relnamespace = n.oid
|
||||
);
|
||||
|
||||
RETURN ''geometry_columns table is now linked to the system tables'';
|
||||
|
||||
END;
|
||||
'
|
||||
LANGUAGE 'plpgsql' ;
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- ADDGEOMETRYCOLUMN (
|
||||
-- <catalog>, <schema>, <table name>, <column name>,
|
||||
-- <srid>, <type>, <dim> )
|
||||
--
|
||||
-- Type can be one of geometry, GEOMETRYCOLLECTION, POINT, MULTIPOINT, POLYGON,
|
||||
-- MULTIPOLYGON, LINESTRING, or MULTILINESTRING.
|
||||
--
|
||||
-- Types (except geometry) are checked for consistency using a CHECK constraint
|
||||
-- uses SQL ALTER TABLE command to add the geometry column to the table.
|
||||
-- Addes a row to geometry_columns.
|
||||
-- Addes a constraint on the table that all the geometries MUST have the same
|
||||
-- SRID. Checks the coord_dimension to make sure its between 0 and 3.
|
||||
-- Should also check the precision grid (future expansion).
|
||||
-- Calls fix_geometry_columns() at the end.
|
||||
--
|
||||
CREATE FUNCTION AddGeometryColumn(varchar,varchar,varchar,varchar,integer,varchar,integer)
|
||||
RETURNS text
|
||||
AS
|
||||
'
|
||||
DECLARE
|
||||
catalog_name alias for $1;
|
||||
schema_name alias for $2;
|
||||
table_name alias for $3;
|
||||
column_name alias for $4;
|
||||
new_srid alias for $5;
|
||||
new_type alias for $6;
|
||||
new_dim alias for $7;
|
||||
|
||||
rec RECORD;
|
||||
schema_ok bool;
|
||||
real_schema name;
|
||||
BEGIN
|
||||
|
||||
IF ( not ( (new_type =''GEOMETRY'') or
|
||||
(new_type =''GEOMETRYCOLLECTION'') or
|
||||
(new_type =''POINT'') or
|
||||
(new_type =''MULTIPOINT'') or
|
||||
(new_type =''POLYGON'') or
|
||||
(new_type =''MULTIPOLYGON'') or
|
||||
(new_type =''LINESTRING'') or
|
||||
(new_type =''MULTILINESTRING'')) )
|
||||
THEN
|
||||
RAISE EXCEPTION ''Invalid type name - valid ones are:
|
||||
GEOMETRY, GEOMETRYCOLLECTION, POINT,
|
||||
MULTIPOINT, POLYGON, MULTIPOLYGON,
|
||||
LINESTRING, or MULTILINESTRING '';
|
||||
RETURN ''fail'';
|
||||
END IF;
|
||||
|
||||
IF ( (new_dim >3) or (new_dim <0) ) THEN
|
||||
RAISE EXCEPTION ''invalid dimension'';
|
||||
RETURN ''fail'';
|
||||
END IF;
|
||||
|
||||
IF ( schema_name != '''' ) THEN
|
||||
schema_ok = ''f'';
|
||||
FOR rec IN SELECT nspname FROM pg_namespace WHERE text(nspname) = schema_name LOOP
|
||||
schema_ok := ''t'';
|
||||
END LOOP;
|
||||
|
||||
if ( schema_ok <> ''t'' ) THEN
|
||||
RAISE NOTICE ''Invalid schema name - using current_schema()'';
|
||||
SELECT current_schema() into real_schema;
|
||||
ELSE
|
||||
real_schema = schema_name;
|
||||
END IF;
|
||||
|
||||
ELSE
|
||||
SELECT current_schema() into real_schema;
|
||||
END IF;
|
||||
|
||||
EXECUTE ''ALTER TABLE '' || quote_ident(real_schema) ||
|
||||
''.'' || quote_ident(table_name) ||
|
||||
'' ADD COLUMN '' || quote_ident(column_name) ||
|
||||
'' geometry '';
|
||||
|
||||
EXECUTE ''ALTER TABLE '' || quote_ident(real_schema) ||
|
||||
''.'' || quote_ident(table_name) ||
|
||||
'' ADD CHECK (SRID('' || quote_ident(column_name) ||
|
||||
'') = '' || new_srid || '')'' ;
|
||||
|
||||
IF (not(new_type = ''GEOMETRY'')) THEN
|
||||
EXECUTE ''ALTER TABLE '' || quote_ident(real_schema) ||
|
||||
''.'' || quote_ident(table_name) ||
|
||||
'' ADD CHECK (geometrytype('' ||
|
||||
quote_ident(column_name) || '')='' ||
|
||||
quote_literal(new_type) || '' OR ('' ||
|
||||
quote_ident(column_name) || '') is null)'';
|
||||
END IF;
|
||||
|
||||
EXECUTE ''INSERT INTO geometry_columns VALUES ('' ||
|
||||
quote_literal('''') || '','' ||
|
||||
quote_literal(real_schema) || '','' ||
|
||||
quote_literal(table_name) || '','' ||
|
||||
quote_literal(column_name) || '','' ||
|
||||
new_dim || '','' || new_srid || '','' ||
|
||||
quote_literal(new_type) || '')'';
|
||||
|
||||
EXECUTE ''select fix_geometry_columns()'';
|
||||
--SELECT fix_geometry_columns();
|
||||
|
||||
return ''Geometry column '' || column_name || '' added to table ''
|
||||
|| real_schema || ''.'' || table_name || '' WITH a SRID of '' || new_srid ||
|
||||
'' and type '' || new_type;
|
||||
END;
|
||||
' LANGUAGE 'plpgsql' WITH (isstrict);
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- ADDGEOMETRYCOLUMN ( <schema>, <table>, <column>, <srid>, <type>, <dim> )
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
CREATE FUNCTION AddGeometryColumn(varchar,varchar,varchar,integer,varchar,integer) RETURNS text AS '
|
||||
DECLARE
|
||||
ret text;
|
||||
BEGIN
|
||||
SELECT AddGeometryColumn('''',$1,$2,$3,$4,$5,$6) into ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
' LANGUAGE 'plpgsql' WITH (isstrict);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- DROPGEOMETRYCOLUMN( <schema name>, <table name>, <column name> )
|
||||
--
|
||||
-- Removes geometry column reference from geometry_columns table,
|
||||
-- and actually drops the column.
|
||||
--
|
||||
CREATE FUNCTION DropGeometryColumn(varchar,varchar,varchar)
|
||||
RETURNS text
|
||||
AS
|
||||
'
|
||||
DECLARE
|
||||
schema_name alias for $1;
|
||||
table_name alias for $2;
|
||||
column_name alias for $3;
|
||||
|
||||
myrec RECORD;
|
||||
real_schema name;
|
||||
okay boolean;
|
||||
query text;
|
||||
|
||||
BEGIN
|
||||
|
||||
|
||||
-- Find, check or fix schema_name
|
||||
IF ( schema_name != '''' ) THEN
|
||||
okay = ''f'';
|
||||
|
||||
FOR myrec IN SELECT nspname FROM pg_namespace WHERE text(nspname) = schema_name LOOP
|
||||
okay := ''t'';
|
||||
END LOOP;
|
||||
|
||||
IF ( okay <> ''t'' ) THEN
|
||||
RAISE NOTICE ''Invalid schema name - using current_schema()'';
|
||||
SELECT current_schema() into real_schema;
|
||||
ELSE
|
||||
real_schema = schema_name;
|
||||
END IF;
|
||||
ELSE
|
||||
SELECT current_schema() into real_schema;
|
||||
END IF;
|
||||
|
||||
-- first we find out if the column is in the geometry_columns table
|
||||
okay = ''f'';
|
||||
FOR myrec IN SELECT * from geometry_columns where f_table_schema = text(real_schema) and f_table_name = table_name and f_geometry_column = column_name LOOP
|
||||
okay := ''t'';
|
||||
END LOOP;
|
||||
IF (okay <> ''t'') THEN
|
||||
RAISE EXCEPTION ''column not found in geometry_columns table'';
|
||||
RETURN ''f'';
|
||||
END IF;
|
||||
|
||||
|
||||
-- Remove ref from geometry_columns table
|
||||
EXECUTE ''delete from geometry_columns where f_table_schema = '' ||
|
||||
quote_literal(real_schema) || '' and f_table_name = '' ||
|
||||
quote_literal(table_name) || '' and f_geometry_column = '' ||
|
||||
quote_literal(column_name);
|
||||
|
||||
-- Remove table column
|
||||
EXECUTE ''ALTER TABLE '' || quote_ident(real_schema) || ''.'' ||
|
||||
quote_ident(table_name) || '' DROP COLUMN '' ||
|
||||
quote_ident(column_name);
|
||||
|
||||
|
||||
RETURN real_schema || ''.'' || table_name || ''.'' || column_name ||'' effectively removed.'';
|
||||
|
||||
END;
|
||||
'
|
||||
LANGUAGE 'plpgsql' WITH (isstrict);
|
||||
|
||||
|
||||
|
||||
END TRANSACTION;
|
|
@ -1,164 +0,0 @@
|
|||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
--
|
||||
-- $Id$
|
||||
--
|
||||
-- PostGIS - Spatial Types for PostgreSQL
|
||||
-- http://postgis.refractions.net
|
||||
-- Copyright 2001-2003 Refractions Research Inc.
|
||||
--
|
||||
-- This is free software; you can redistribute and/or modify it under
|
||||
-- the terms of hte GNU General Public Licence. See the COPYING file.
|
||||
--
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- $Log$
|
||||
-- Revision 1.2 2003/07/01 18:30:55 pramsey
|
||||
-- Added CVS revision headers.
|
||||
--
|
||||
--
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
-- You might have to define the PL/PgSQL language usually done with the
|
||||
-- changelang script.
|
||||
|
||||
-- Here's some hokey code to test to see if PL/PgSQL is installed
|
||||
-- if it is, you get a message "PL/PgSQL is installed"
|
||||
-- otherwise it will give a big error message.
|
||||
|
||||
(select 'PL/PgSQL is installed.' as message from pg_language where lanname='plpgsql') union (select 'You must install PL/PgSQL before running this SQL file,\nor you will get an error. To install PL/PgSQL run:\n\tcreatelang plpgsql <dbname>'::text as message) order by message limit 1;
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- HISTOGRAM2D
|
||||
|
||||
CREATE FUNCTION histogram2d_in(cstring)
|
||||
RETURNS histogram2d
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION histogram2d_out(histogram2d)
|
||||
RETURNS cstring
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE histogram2d (
|
||||
alignment = double,
|
||||
internallength = variable,
|
||||
input = histogram2d_in,
|
||||
output = histogram2d_out,
|
||||
storage = main
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- BOX3D
|
||||
|
||||
CREATE FUNCTION box3d_in(cstring)
|
||||
RETURNS box3d
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION box3d_out(box3d)
|
||||
RETURNS cstring
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE box3d (
|
||||
alignment = double,
|
||||
internallength = 48,
|
||||
input = box3d_in,
|
||||
output = box3d_out
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- SPHEROID
|
||||
|
||||
CREATE FUNCTION spheroid_in(cstring)
|
||||
RETURNS spheroid
|
||||
AS '@MODULE_FILENAME@','ellipsoid_in'
|
||||
LANGUAGE 'C' WITH (isstrict,iscachable);
|
||||
|
||||
CREATE FUNCTION spheroid_out(spheroid)
|
||||
RETURNS cstring
|
||||
AS '@MODULE_FILENAME@','ellipsoid_out'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE spheroid (
|
||||
alignment = double,
|
||||
internallength = 65,
|
||||
input = spheroid_in,
|
||||
output = spheroid_out
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- WKB
|
||||
|
||||
CREATE FUNCTION wkb_in(cstring)
|
||||
RETURNS wkb
|
||||
AS '@MODULE_FILENAME@','WKB_in'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION wkb_out(wkb)
|
||||
RETURNS cstring
|
||||
AS '@MODULE_FILENAME@','WKB_out'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE wkb (
|
||||
internallength = variable,
|
||||
input = wkb_in,
|
||||
output = wkb_out,
|
||||
storage = extended
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- CHIP
|
||||
|
||||
CREATE FUNCTION chip_in(cstring)
|
||||
RETURNS chip
|
||||
AS '@MODULE_FILENAME@','CHIP_in'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION chip_out(chip)
|
||||
RETURNS cstring
|
||||
AS '@MODULE_FILENAME@','CHIP_out'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE chip (
|
||||
alignment = double,
|
||||
internallength = variable,
|
||||
input = chip_in,
|
||||
output = chip_out,
|
||||
storage = extended
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- GEOMETRY
|
||||
|
||||
CREATE FUNCTION geometry_in(cstring)
|
||||
RETURNS geometry
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION geometry_out(geometry)
|
||||
RETURNS cstring
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE geometry (
|
||||
alignment = double,
|
||||
internallength = variable,
|
||||
input = geometry_in,
|
||||
output = geometry_out,
|
||||
storage = main
|
||||
);
|
||||
|
||||
--
|
||||
-- GiST selectivity function
|
||||
--
|
||||
|
||||
CREATE FUNCTION postgis_gist_sel (internal, oid, internal, int4)
|
||||
RETURNS float8
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
|
|
@ -1,491 +0,0 @@
|
|||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
--
|
||||
-- $Id$
|
||||
--
|
||||
-- PostGIS - Spatial Types for PostgreSQL
|
||||
-- http://postgis.refractions.net
|
||||
-- Copyright 2001-2003 Refractions Research Inc.
|
||||
--
|
||||
-- This is free software; you can redistribute and/or modify it under
|
||||
-- the terms of hte GNU General Public Licence. See the COPYING file.
|
||||
--
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- $Log$
|
||||
-- Revision 1.9 2004/01/20 20:14:17 strk
|
||||
-- cleaner comments for DropGeometryColumn
|
||||
--
|
||||
-- Revision 1.8 2004/01/20 20:10:39 strk
|
||||
-- removed bogus comment about missed alter table drop column
|
||||
--
|
||||
-- Revision 1.7 2003/12/30 10:40:21 strk
|
||||
-- For all versions:
|
||||
-- Updated fix_geometry_columns to use a more readable format in queries.
|
||||
--
|
||||
-- For PG >= 73:
|
||||
-- Updated fix_geometry_columns() to consider schema when fixing attrelid and
|
||||
-- varattnum, also changed empty value to 'public' string for records with
|
||||
-- an invalid schema specification.
|
||||
-- Updated DropGeometryColumn to actually issue the
|
||||
-- ALTER TABLE DROP COLUMN query.
|
||||
--
|
||||
-- Revision 1.6 2003/12/23 09:00:12 strk
|
||||
-- AddGeometryColumn, DropGeometryColum moved to version-specific scripts.
|
||||
-- Schema support enabled for version 73 and 74.
|
||||
--
|
||||
-- Revision 1.5 2003/12/18 18:07:06 strk
|
||||
-- Changed fix_geometry_columns() for PG >= 73 so to set f_table_schema to
|
||||
-- the empty string if its value is not a valid pg namespace.
|
||||
--
|
||||
-- Revision 1.4 2003/11/28 11:25:31 strk
|
||||
-- Added explicit geometry as text cast
|
||||
--
|
||||
-- Revision 1.3 2003/11/28 11:06:49 strk
|
||||
-- Added WKB_recv function for binary WKB input
|
||||
--
|
||||
-- Revision 1.2 2003/11/19 15:29:21 strk
|
||||
-- Added default btree operator class for PG7.4
|
||||
--
|
||||
-- Revision 1.1 2003/11/11 10:38:23 strk
|
||||
-- Postgresql 7.4 enabler scripts.
|
||||
--
|
||||
-- Revision 1.4 2003/07/01 18:30:55 pramsey
|
||||
-- Added CVS revision headers.
|
||||
--
|
||||
--
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- WKB
|
||||
|
||||
-- this has been moved here at _end from _start
|
||||
-- because we need the definition of function bytea
|
||||
-- found in _common
|
||||
CREATE TYPE wkb (
|
||||
internallength = variable,
|
||||
input = wkb_in,
|
||||
output = wkb_out,
|
||||
storage = extended,
|
||||
send = bytea,
|
||||
receive = wkb_recv
|
||||
);
|
||||
|
||||
--
|
||||
-- 7.3 explicit casting definitions
|
||||
--
|
||||
|
||||
CREATE CAST ( chip AS geometry ) WITH FUNCTION geometry(chip) AS IMPLICIT;
|
||||
CREATE CAST ( geometry AS box3d ) WITH FUNCTION box3d(geometry) AS IMPLICIT;
|
||||
CREATE CAST ( geometry AS box ) WITH FUNCTION box(geometry) AS IMPLICIT;
|
||||
CREATE CAST ( box3d AS geometry ) WITH FUNCTION geometry(box3d) AS IMPLICIT;
|
||||
CREATE CAST ( text AS geometry) WITH FUNCTION geometry(text) AS IMPLICIT;
|
||||
CREATE CAST ( wkb AS bytea ) WITH FUNCTION bytea(wkb) AS IMPLICIT;
|
||||
CREATE CAST ( box3d AS box ) WITH FUNCTION box3dtobox(box3d);
|
||||
CREATE CAST ( geometry AS text ) WITH FUNCTION astext(geometry);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- UPDATE_GEOMETRY_STATS()
|
||||
|
||||
CREATE FUNCTION update_geometry_stats()
|
||||
RETURNS text
|
||||
AS
|
||||
'
|
||||
BEGIN
|
||||
EXECUTE ''update geometry_columns set attrelid = (select pg_class.oid AS attrelid from pg_class,pg_attribute where relname =geometry_columns.f_table_name::name and pg_attribute.attrelid = pg_class.oid and pg_attribute.attname = geometry_columns.f_geometry_column::name), varattnum = (select pg_attribute.attnum from pg_class,pg_attribute where relname =geometry_columns.f_table_name::name and pg_attribute.attrelid = pg_class.oid and pg_attribute.attname = geometry_columns.f_geometry_column::name)'';
|
||||
execute ''update geometry_columns set stats = (build_histogram2d( create_histogram2d(find_extent(f_table_name,f_geometry_column),40 ),f_table_name::text, f_geometry_column::text)) '';
|
||||
return ''done'';
|
||||
END;
|
||||
'
|
||||
LANGUAGE 'plpgsql' ;
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- UPDATE_GEOMETRY_STATS( <table>, <column> )
|
||||
|
||||
CREATE FUNCTION update_geometry_stats(varchar,varchar)
|
||||
RETURNS text
|
||||
AS
|
||||
'
|
||||
DECLARE
|
||||
tablename aliAS for $1;
|
||||
columnname aliAS for $2;
|
||||
|
||||
BEGIN
|
||||
EXECUTE ''update geometry_columns set attrelid = (select pg_class.oid AS attrelid from pg_class,pg_attribute where relname =geometry_columns.f_table_name::name and pg_attribute.attrelid = pg_class.oid and pg_attribute.attname = geometry_columns.f_geometry_column::name), varattnum = (select pg_attribute.attnum from pg_class,pg_attribute where relname =geometry_columns.f_table_name::name and pg_attribute.attrelid = pg_class.oid and pg_attribute.attname = geometry_columns.f_geometry_column::name)'';
|
||||
execute ''update geometry_columns set stats = (build_histogram2d( create_histogram2d(find_extent(''|| quote_literal(tablename) || '',''||quote_literal(columnname) ||''),40 ),''|| quote_literal(tablename) || ''::text,''||quote_literal(columnname) ||''::text )) WHERE f_table_name=''|| quote_literal(tablename) || ''and f_geometry_column=''||quote_literal(columnname) ;
|
||||
return ''done'';
|
||||
END;
|
||||
'
|
||||
LANGUAGE 'plpgsql' ;
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- CREATE_HISTOGRAM2D( <box>, <size> )
|
||||
--
|
||||
-- Returns a histgram with 0s in all the boxes.
|
||||
|
||||
CREATE FUNCTION create_histogram2d(box3d,int)
|
||||
RETURNS histogram2d
|
||||
AS '@MODULE_FILENAME@','create_histogram2d'
|
||||
LANGUAGE 'C' with (isstrict);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- BUILD_HISTOGRAM2D( <histogram2d>, <tablename>, <columnname> )
|
||||
--
|
||||
|
||||
CREATE FUNCTION build_histogram2d (histogram2d, text, text)
|
||||
RETURNS histogram2d
|
||||
AS '@MODULE_FILENAME@','build_histogram2d'
|
||||
LANGUAGE 'C' with (isstrict);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- EXPLODE_HISTOGRAM2D( <histogram2d>, <tablename> )
|
||||
--
|
||||
|
||||
CREATE FUNCTION explode_histogram2d (histogram2d, text)
|
||||
RETURNS histogram2d
|
||||
AS '@MODULE_FILENAME@','explode_histogram2d'
|
||||
LANGUAGE 'C' with (isstrict);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- ESTIMATE_HISTOGRAM2D( <histogram2d>, <box> )
|
||||
--
|
||||
|
||||
CREATE FUNCTION estimate_histogram2d(histogram2d,box)
|
||||
RETURNS float8
|
||||
AS '@MODULE_FILENAME@','estimate_histogram2d'
|
||||
LANGUAGE 'C' with (isstrict);
|
||||
|
||||
CREATE FUNCTION postgisgistcostestimate(internal,internal,internal,internal,internal,internal,internal,internal)
|
||||
RETURNS opaque
|
||||
AS '@MODULE_FILENAME@','postgisgistcostestimate'
|
||||
LANGUAGE 'C' with (isstrict);
|
||||
|
||||
--
|
||||
-- 7.2 GiST support functions
|
||||
--
|
||||
|
||||
CREATE FUNCTION ggeometry_consistent(internal,geometry,int4)
|
||||
RETURNS bool
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION ggeometry_compress(internal)
|
||||
RETURNS internal
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION gbox_penalty(internal,internal,internal)
|
||||
RETURNS internal
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION gbox_picksplit(internal, internal)
|
||||
RETURNS internal
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION gbox_union(bytea, internal)
|
||||
RETURNS internal
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION gbox_same(box, box, internal)
|
||||
RETURNS internal
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION rtree_decompress(internal)
|
||||
RETURNS internal
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
--
|
||||
-- 7.2 RTREE support functions
|
||||
--
|
||||
|
||||
CREATE FUNCTION geometry_union(geometry,geometry)
|
||||
RETURNS geometry
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION geometry_inter(geometry,geometry)
|
||||
RETURNS geometry
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION geometry_size(geometry,internal)
|
||||
RETURNS float4
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
--
|
||||
-- Create opclass index bindings
|
||||
--
|
||||
|
||||
CREATE OPERATOR CLASS gist_geometry_ops
|
||||
DEFAULT FOR TYPE geometry USING gist AS
|
||||
OPERATOR 1 << ,
|
||||
OPERATOR 2 &< ,
|
||||
OPERATOR 3 && ,
|
||||
OPERATOR 4 &> ,
|
||||
OPERATOR 5 >> ,
|
||||
OPERATOR 6 ~= ,
|
||||
OPERATOR 7 ~ ,
|
||||
OPERATOR 8 @ ,
|
||||
FUNCTION 1 ggeometry_consistent (internal, geometry, int4),
|
||||
FUNCTION 2 gbox_union (bytea, internal),
|
||||
FUNCTION 3 ggeometry_compress (internal),
|
||||
FUNCTION 4 rtree_decompress (internal),
|
||||
FUNCTION 5 gbox_penalty (internal, internal, internal),
|
||||
FUNCTION 6 gbox_picksplit (internal, internal),
|
||||
FUNCTION 7 gbox_same (box, box, internal);
|
||||
|
||||
UPDATE pg_opclass
|
||||
SET opckeytype = (select oid from pg_type where typname = 'box')
|
||||
WHERE opcname = 'gist_geometry_ops';
|
||||
|
||||
CREATE OPERATOR CLASS btree_geometry_ops
|
||||
DEFAULT FOR TYPE geometry USING btree AS
|
||||
OPERATOR 1 < ,
|
||||
OPERATOR 2 <= ,
|
||||
OPERATOR 3 = ,
|
||||
OPERATOR 4 >= ,
|
||||
OPERATOR 5 > ,
|
||||
FUNCTION 1 geometry_cmp (geometry, geometry);
|
||||
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- FIX_GEOMETRY_COLUMNS()
|
||||
--
|
||||
-- Since 7.3 schema support has been added.
|
||||
-- Previous postgis versions used to put the database name in
|
||||
-- the schema column. This needs to be fixed, so we set to the
|
||||
-- empty string any schema value not existing in pg_namespace
|
||||
--
|
||||
|
||||
CREATE FUNCTION fix_geometry_columns() RETURNS text
|
||||
AS
|
||||
'
|
||||
BEGIN
|
||||
-- it would be better to find the correct schema name
|
||||
UPDATE geometry_columns SET f_table_schema = ''public''
|
||||
WHERE f_table_schema is NULL or f_table_schema NOT IN
|
||||
( SELECT nspname::varchar FROM pg_namespace );
|
||||
|
||||
UPDATE geometry_columns SET attrelid = (
|
||||
SELECT c.oid
|
||||
FROM pg_class c, pg_attribute a, pg_namespace n
|
||||
WHERE c.relname = geometry_columns.f_table_name::name
|
||||
AND a.attrelid = c.oid AND c.relnamespace = n.oid
|
||||
AND a.attname = geometry_columns.f_geometry_column::name
|
||||
AND n.nspname = geometry_columns.f_table_schema::name
|
||||
);
|
||||
|
||||
UPDATE geometry_columns SET varattnum = (
|
||||
SELECT a.attnum
|
||||
FROM pg_class c, pg_attribute a, pg_namespace n
|
||||
WHERE n.nspname = geometry_columns.f_table_schema::name
|
||||
AND c.relname = geometry_columns.f_table_name::name
|
||||
AND a.attname = geometry_columns.f_geometry_column::name
|
||||
AND a.attrelid = c.oid AND c.relnamespace = n.oid
|
||||
);
|
||||
|
||||
RETURN ''geometry_columns table is now linked to the system tables'';
|
||||
|
||||
|
||||
END;
|
||||
'
|
||||
LANGUAGE 'plpgsql' ;
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- ADDGEOMETRYCOLUMN (
|
||||
-- <catalog>, <schema>, <table name>, <column name>,
|
||||
-- <srid>, <type>, <dim> )
|
||||
--
|
||||
-- Type can be one of geometry, GEOMETRYCOLLECTION, POINT, MULTIPOINT, POLYGON,
|
||||
-- MULTIPOLYGON, LINESTRING, or MULTILINESTRING.
|
||||
--
|
||||
-- Types (except geometry) are checked for consistency using a CHECK constraint
|
||||
-- uses SQL ALTER TABLE command to add the geometry column to the table.
|
||||
-- Addes a row to geometry_columns.
|
||||
-- Addes a constraint on the table that all the geometries MUST have the same
|
||||
-- SRID. Checks the coord_dimension to make sure its between 0 and 3.
|
||||
-- Should also check the precision grid (future expansion).
|
||||
-- Calls fix_geometry_columns() at the end.
|
||||
--
|
||||
CREATE FUNCTION AddGeometryColumn(varchar,varchar,varchar,varchar,integer,varchar,integer)
|
||||
RETURNS text
|
||||
AS
|
||||
'
|
||||
DECLARE
|
||||
catalog_name alias for $1;
|
||||
schema_name alias for $2;
|
||||
table_name alias for $3;
|
||||
column_name alias for $4;
|
||||
new_srid alias for $5;
|
||||
new_type alias for $6;
|
||||
new_dim alias for $7;
|
||||
|
||||
rec RECORD;
|
||||
schema_ok bool;
|
||||
real_schema name;
|
||||
BEGIN
|
||||
|
||||
IF ( not ( (new_type =''GEOMETRY'') or
|
||||
(new_type =''GEOMETRYCOLLECTION'') or
|
||||
(new_type =''POINT'') or
|
||||
(new_type =''MULTIPOINT'') or
|
||||
(new_type =''POLYGON'') or
|
||||
(new_type =''MULTIPOLYGON'') or
|
||||
(new_type =''LINESTRING'') or
|
||||
(new_type =''MULTILINESTRING'')) )
|
||||
THEN
|
||||
RAISE EXCEPTION ''Invalid type name - valid ones are:
|
||||
GEOMETRY, GEOMETRYCOLLECTION, POINT,
|
||||
MULTIPOINT, POLYGON, MULTIPOLYGON,
|
||||
LINESTRING, or MULTILINESTRING '';
|
||||
RETURN ''fail'';
|
||||
END IF;
|
||||
|
||||
IF ( (new_dim >3) or (new_dim <0) ) THEN
|
||||
RAISE EXCEPTION ''invalid dimension'';
|
||||
RETURN ''fail'';
|
||||
END IF;
|
||||
|
||||
IF ( schema_name != '''' ) THEN
|
||||
schema_ok = ''f'';
|
||||
FOR rec IN SELECT nspname FROM pg_namespace WHERE text(nspname) = schema_name LOOP
|
||||
schema_ok := ''t'';
|
||||
END LOOP;
|
||||
|
||||
if ( schema_ok <> ''t'' ) THEN
|
||||
RAISE NOTICE ''Invalid schema name - using current_schema()'';
|
||||
SELECT current_schema() into real_schema;
|
||||
ELSE
|
||||
real_schema = schema_name;
|
||||
END IF;
|
||||
|
||||
ELSE
|
||||
SELECT current_schema() into real_schema;
|
||||
END IF;
|
||||
|
||||
EXECUTE ''ALTER TABLE '' || quote_ident(real_schema) ||
|
||||
''.'' || quote_ident(table_name) ||
|
||||
'' ADD COLUMN '' || quote_ident(column_name) ||
|
||||
'' geometry '';
|
||||
|
||||
EXECUTE ''ALTER TABLE '' || quote_ident(real_schema) ||
|
||||
''.'' || quote_ident(table_name) ||
|
||||
'' ADD CHECK (SRID('' || quote_ident(column_name) ||
|
||||
'') = '' || new_srid || '')'' ;
|
||||
|
||||
IF (not(new_type = ''GEOMETRY'')) THEN
|
||||
EXECUTE ''ALTER TABLE '' || quote_ident(real_schema) ||
|
||||
''.'' || quote_ident(table_name) ||
|
||||
'' ADD CHECK (geometrytype('' ||
|
||||
quote_ident(column_name) || '')='' ||
|
||||
quote_literal(new_type) || '' OR ('' ||
|
||||
quote_ident(column_name) || '') is null)'';
|
||||
END IF;
|
||||
|
||||
EXECUTE ''INSERT INTO geometry_columns VALUES ('' ||
|
||||
quote_literal('''') || '','' ||
|
||||
quote_literal(real_schema) || '','' ||
|
||||
quote_literal(table_name) || '','' ||
|
||||
quote_literal(column_name) || '','' ||
|
||||
new_dim || '','' || new_srid || '','' ||
|
||||
quote_literal(new_type) || '')'';
|
||||
|
||||
EXECUTE ''select fix_geometry_columns()'';
|
||||
--SELECT fix_geometry_columns();
|
||||
|
||||
return ''Geometry column '' || column_name || '' added to table ''
|
||||
|| real_schema || ''.'' || table_name || '' WITH a SRID of '' || new_srid ||
|
||||
'' and type '' || new_type;
|
||||
END;
|
||||
' LANGUAGE 'plpgsql' WITH (isstrict);
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- ADDGEOMETRYCOLUMN ( <schema>, <table>, <column>, <srid>, <type>, <dim> )
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
CREATE FUNCTION AddGeometryColumn(varchar,varchar,varchar,integer,varchar,integer) RETURNS text AS '
|
||||
DECLARE
|
||||
ret text;
|
||||
BEGIN
|
||||
SELECT AddGeometryColumn('''',$1,$2,$3,$4,$5,$6) into ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
' LANGUAGE 'plpgsql' WITH (isstrict);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- DROPGEOMETRYCOLUMN( <schema name>, <table name>, <column name> )
|
||||
--
|
||||
-- Removes geometry column reference from geometry_columns table,
|
||||
-- and actually drops the column.
|
||||
--
|
||||
CREATE FUNCTION DropGeometryColumn(varchar,varchar,varchar)
|
||||
RETURNS text
|
||||
AS
|
||||
'
|
||||
DECLARE
|
||||
schema_name alias for $1;
|
||||
table_name alias for $2;
|
||||
column_name alias for $3;
|
||||
|
||||
myrec RECORD;
|
||||
real_schema name;
|
||||
okay boolean;
|
||||
query text;
|
||||
|
||||
BEGIN
|
||||
|
||||
|
||||
-- Find, check or fix schema_name
|
||||
IF ( schema_name != '''' ) THEN
|
||||
okay = ''f'';
|
||||
|
||||
FOR myrec IN SELECT nspname FROM pg_namespace WHERE text(nspname) = schema_name LOOP
|
||||
okay := ''t'';
|
||||
END LOOP;
|
||||
|
||||
IF ( okay <> ''t'' ) THEN
|
||||
RAISE NOTICE ''Invalid schema name - using current_schema()'';
|
||||
SELECT current_schema() into real_schema;
|
||||
ELSE
|
||||
real_schema = schema_name;
|
||||
END IF;
|
||||
ELSE
|
||||
SELECT current_schema() into real_schema;
|
||||
END IF;
|
||||
|
||||
-- first we find out if the column is in the geometry_columns table
|
||||
okay = ''f'';
|
||||
FOR myrec IN SELECT * from geometry_columns where f_table_schema = text(real_schema) and f_table_name = table_name and f_geometry_column = column_name LOOP
|
||||
okay := ''t'';
|
||||
END LOOP;
|
||||
IF (okay <> ''t'') THEN
|
||||
RAISE EXCEPTION ''column not found in geometry_columns table'';
|
||||
RETURN ''f'';
|
||||
END IF;
|
||||
|
||||
|
||||
-- Remove ref from geometry_columns table
|
||||
EXECUTE ''delete from geometry_columns where f_table_schema = '' ||
|
||||
quote_literal(real_schema) || '' and f_table_name = '' ||
|
||||
quote_literal(table_name) || '' and f_geometry_column = '' ||
|
||||
quote_literal(column_name);
|
||||
|
||||
-- Remove table column
|
||||
EXECUTE ''ALTER TABLE '' || quote_ident(real_schema) || ''.'' ||
|
||||
quote_ident(table_name) || '' DROP COLUMN '' ||
|
||||
quote_ident(column_name);
|
||||
|
||||
|
||||
RETURN real_schema || ''.'' || table_name || ''.'' || column_name ||'' effectively removed.'';
|
||||
|
||||
END;
|
||||
'
|
||||
LANGUAGE 'plpgsql' WITH (isstrict);
|
||||
|
||||
|
||||
|
||||
|
||||
END TRANSACTION;
|
|
@ -1,169 +0,0 @@
|
|||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
--
|
||||
-- $Id$
|
||||
--
|
||||
-- PostGIS - Spatial Types for PostgreSQL
|
||||
-- http://postgis.refractions.net
|
||||
-- Copyright 2001-2003 Refractions Research Inc.
|
||||
--
|
||||
-- This is free software; you can redistribute and/or modify it under
|
||||
-- the terms of hte GNU General Public Licence. See the COPYING file.
|
||||
--
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- $Log$
|
||||
-- Revision 1.2 2003/11/28 11:06:49 strk
|
||||
-- Added WKB_recv function for binary WKB input
|
||||
--
|
||||
-- Revision 1.1 2003/11/11 10:38:23 strk
|
||||
-- Postgresql 7.4 enabler scripts.
|
||||
--
|
||||
-- Revision 1.2 2003/07/01 18:30:55 pramsey
|
||||
-- Added CVS revision headers.
|
||||
--
|
||||
--
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
-- You might have to define the PL/PgSQL language usually done with the
|
||||
-- changelang script.
|
||||
|
||||
-- Here's some hokey code to test to see if PL/PgSQL is installed
|
||||
-- if it is, you get a message "PL/PgSQL is installed"
|
||||
-- otherwise it will give a big error message.
|
||||
|
||||
(select 'PL/PgSQL is installed.' as message from pg_language where lanname='plpgsql') union (select 'You must install PL/PgSQL before running this SQL file,\nor you will get an error. To install PL/PgSQL run:\n\tcreatelang plpgsql <dbname>'::text as message) order by message limit 1;
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- HISTOGRAM2D
|
||||
|
||||
CREATE FUNCTION histogram2d_in(cstring)
|
||||
RETURNS histogram2d
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION histogram2d_out(histogram2d)
|
||||
RETURNS cstring
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE histogram2d (
|
||||
alignment = double,
|
||||
internallength = variable,
|
||||
input = histogram2d_in,
|
||||
output = histogram2d_out,
|
||||
storage = main
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- BOX3D
|
||||
|
||||
CREATE FUNCTION box3d_in(cstring)
|
||||
RETURNS box3d
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION box3d_out(box3d)
|
||||
RETURNS cstring
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE box3d (
|
||||
alignment = double,
|
||||
internallength = 48,
|
||||
input = box3d_in,
|
||||
output = box3d_out
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- SPHEROID
|
||||
|
||||
CREATE FUNCTION spheroid_in(cstring)
|
||||
RETURNS spheroid
|
||||
AS '@MODULE_FILENAME@','ellipsoid_in'
|
||||
LANGUAGE 'C' WITH (isstrict,iscachable);
|
||||
|
||||
CREATE FUNCTION spheroid_out(spheroid)
|
||||
RETURNS cstring
|
||||
AS '@MODULE_FILENAME@','ellipsoid_out'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE spheroid (
|
||||
alignment = double,
|
||||
internallength = 65,
|
||||
input = spheroid_in,
|
||||
output = spheroid_out
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- WKB
|
||||
|
||||
CREATE FUNCTION wkb_in(cstring)
|
||||
RETURNS wkb
|
||||
AS '@MODULE_FILENAME@','WKB_in'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION wkb_out(wkb)
|
||||
RETURNS cstring
|
||||
AS '@MODULE_FILENAME@','WKB_out'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION wkb_recv(internal)
|
||||
RETURNS wkb
|
||||
AS '@MODULE_FILENAME@','WKB_recv'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- CHIP
|
||||
|
||||
CREATE FUNCTION chip_in(cstring)
|
||||
RETURNS chip
|
||||
AS '@MODULE_FILENAME@','CHIP_in'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION chip_out(chip)
|
||||
RETURNS cstring
|
||||
AS '@MODULE_FILENAME@','CHIP_out'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE chip (
|
||||
alignment = double,
|
||||
internallength = variable,
|
||||
input = chip_in,
|
||||
output = chip_out,
|
||||
storage = extended
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- GEOMETRY
|
||||
|
||||
CREATE FUNCTION geometry_in(cstring)
|
||||
RETURNS geometry
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION geometry_out(geometry)
|
||||
RETURNS cstring
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE geometry (
|
||||
alignment = double,
|
||||
internallength = variable,
|
||||
input = geometry_in,
|
||||
output = geometry_out,
|
||||
storage = main
|
||||
);
|
||||
|
||||
--
|
||||
-- GiST selectivity function
|
||||
--
|
||||
|
||||
CREATE FUNCTION postgis_gist_sel (internal, oid, internal, int4)
|
||||
RETURNS float8
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
|
|
@ -1,492 +0,0 @@
|
|||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
--
|
||||
-- $Id$
|
||||
--
|
||||
-- PostGIS - Spatial Types for PostgreSQL
|
||||
-- http://postgis.refractions.net
|
||||
-- Copyright 2001-2003 Refractions Research Inc.
|
||||
--
|
||||
-- This is free software; you can redistribute and/or modify it under
|
||||
-- the terms of hte GNU General Public Licence. See the COPYING file.
|
||||
--
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- $Log$
|
||||
-- Revision 1.2 2004/02/23 12:18:55 strk
|
||||
-- added skeleton functions for pg75 stats integration
|
||||
--
|
||||
-- Revision 1.1 2004/02/04 22:27:02 strk
|
||||
-- Added pg75 support scripts
|
||||
--
|
||||
-- Revision 1.9 2004/01/20 20:14:17 strk
|
||||
-- cleaner comments for DropGeometryColumn
|
||||
--
|
||||
-- Revision 1.8 2004/01/20 20:10:39 strk
|
||||
-- removed bogus comment about missed alter table drop column
|
||||
--
|
||||
-- Revision 1.7 2003/12/30 10:40:21 strk
|
||||
-- For all versions:
|
||||
-- Updated fix_geometry_columns to use a more readable format in queries.
|
||||
--
|
||||
-- For PG >= 73:
|
||||
-- Updated fix_geometry_columns() to consider schema when fixing attrelid and
|
||||
-- varattnum, also changed empty value to 'public' string for records with
|
||||
-- an invalid schema specification.
|
||||
-- Updated DropGeometryColumn to actually issue the
|
||||
-- ALTER TABLE DROP COLUMN query.
|
||||
--
|
||||
-- Revision 1.6 2003/12/23 09:00:12 strk
|
||||
-- AddGeometryColumn, DropGeometryColum moved to version-specific scripts.
|
||||
-- Schema support enabled for version 73 and 74.
|
||||
--
|
||||
-- Revision 1.5 2003/12/18 18:07:06 strk
|
||||
-- Changed fix_geometry_columns() for PG >= 73 so to set f_table_schema to
|
||||
-- the empty string if its value is not a valid pg namespace.
|
||||
--
|
||||
-- Revision 1.4 2003/11/28 11:25:31 strk
|
||||
-- Added explicit geometry as text cast
|
||||
--
|
||||
-- Revision 1.3 2003/11/28 11:06:49 strk
|
||||
-- Added WKB_recv function for binary WKB input
|
||||
--
|
||||
-- Revision 1.2 2003/11/19 15:29:21 strk
|
||||
-- Added default btree operator class for PG7.4
|
||||
--
|
||||
-- Revision 1.1 2003/11/11 10:38:23 strk
|
||||
-- Postgresql 7.4 enabler scripts.
|
||||
--
|
||||
-- Revision 1.4 2003/07/01 18:30:55 pramsey
|
||||
-- Added CVS revision headers.
|
||||
--
|
||||
--
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- WKB
|
||||
|
||||
-- this has been moved here at _end from _start
|
||||
-- because we need the definition of function bytea
|
||||
-- found in _common
|
||||
CREATE TYPE wkb (
|
||||
internallength = variable,
|
||||
input = wkb_in,
|
||||
output = wkb_out,
|
||||
storage = extended,
|
||||
send = bytea,
|
||||
receive = wkb_recv
|
||||
);
|
||||
|
||||
--
|
||||
-- 7.3 explicit casting definitions
|
||||
--
|
||||
|
||||
CREATE CAST ( chip AS geometry ) WITH FUNCTION geometry(chip) AS IMPLICIT;
|
||||
CREATE CAST ( geometry AS box3d ) WITH FUNCTION box3d(geometry) AS IMPLICIT;
|
||||
CREATE CAST ( geometry AS box ) WITH FUNCTION box(geometry) AS IMPLICIT;
|
||||
CREATE CAST ( box3d AS geometry ) WITH FUNCTION geometry(box3d) AS IMPLICIT;
|
||||
CREATE CAST ( text AS geometry) WITH FUNCTION geometry(text) AS IMPLICIT;
|
||||
CREATE CAST ( wkb AS bytea ) WITH FUNCTION bytea(wkb) AS IMPLICIT;
|
||||
CREATE CAST ( box3d AS box ) WITH FUNCTION box3dtobox(box3d);
|
||||
CREATE CAST ( geometry AS text ) WITH FUNCTION astext(geometry);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- UPDATE_GEOMETRY_STATS()
|
||||
|
||||
CREATE FUNCTION update_geometry_stats()
|
||||
RETURNS text
|
||||
AS
|
||||
'
|
||||
BEGIN
|
||||
EXECUTE ''update geometry_columns set attrelid = (select pg_class.oid AS attrelid from pg_class,pg_attribute where relname =geometry_columns.f_table_name::name and pg_attribute.attrelid = pg_class.oid and pg_attribute.attname = geometry_columns.f_geometry_column::name), varattnum = (select pg_attribute.attnum from pg_class,pg_attribute where relname =geometry_columns.f_table_name::name and pg_attribute.attrelid = pg_class.oid and pg_attribute.attname = geometry_columns.f_geometry_column::name)'';
|
||||
execute ''update geometry_columns set stats = (build_histogram2d( create_histogram2d(find_extent(f_table_name,f_geometry_column),40 ),f_table_name::text, f_geometry_column::text)) '';
|
||||
return ''done'';
|
||||
END;
|
||||
'
|
||||
LANGUAGE 'plpgsql' ;
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- UPDATE_GEOMETRY_STATS( <table>, <column> )
|
||||
|
||||
CREATE FUNCTION update_geometry_stats(varchar,varchar)
|
||||
RETURNS text
|
||||
AS
|
||||
'
|
||||
DECLARE
|
||||
tablename aliAS for $1;
|
||||
columnname aliAS for $2;
|
||||
|
||||
BEGIN
|
||||
EXECUTE ''update geometry_columns set attrelid = (select pg_class.oid AS attrelid from pg_class,pg_attribute where relname =geometry_columns.f_table_name::name and pg_attribute.attrelid = pg_class.oid and pg_attribute.attname = geometry_columns.f_geometry_column::name), varattnum = (select pg_attribute.attnum from pg_class,pg_attribute where relname =geometry_columns.f_table_name::name and pg_attribute.attrelid = pg_class.oid and pg_attribute.attname = geometry_columns.f_geometry_column::name)'';
|
||||
execute ''update geometry_columns set stats = (build_histogram2d( create_histogram2d(find_extent(''|| quote_literal(tablename) || '',''||quote_literal(columnname) ||''),40 ),''|| quote_literal(tablename) || ''::text,''||quote_literal(columnname) ||''::text )) WHERE f_table_name=''|| quote_literal(tablename) || ''and f_geometry_column=''||quote_literal(columnname) ;
|
||||
return ''done'';
|
||||
END;
|
||||
'
|
||||
LANGUAGE 'plpgsql' ;
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- CREATE_HISTOGRAM2D( <box>, <size> )
|
||||
--
|
||||
-- Returns a histgram with 0s in all the boxes.
|
||||
|
||||
CREATE FUNCTION create_histogram2d(box3d,int)
|
||||
RETURNS histogram2d
|
||||
AS '@MODULE_FILENAME@','create_histogram2d'
|
||||
LANGUAGE 'C' with (isstrict);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- BUILD_HISTOGRAM2D( <histogram2d>, <tablename>, <columnname> )
|
||||
--
|
||||
|
||||
CREATE FUNCTION build_histogram2d (histogram2d, text, text)
|
||||
RETURNS histogram2d
|
||||
AS '@MODULE_FILENAME@','build_histogram2d'
|
||||
LANGUAGE 'C' with (isstrict);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- EXPLODE_HISTOGRAM2D( <histogram2d>, <tablename> )
|
||||
--
|
||||
|
||||
CREATE FUNCTION explode_histogram2d (histogram2d, text)
|
||||
RETURNS histogram2d
|
||||
AS '@MODULE_FILENAME@','explode_histogram2d'
|
||||
LANGUAGE 'C' with (isstrict);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- ESTIMATE_HISTOGRAM2D( <histogram2d>, <box> )
|
||||
--
|
||||
|
||||
CREATE FUNCTION estimate_histogram2d(histogram2d,box)
|
||||
RETURNS float8
|
||||
AS '@MODULE_FILENAME@','estimate_histogram2d'
|
||||
LANGUAGE 'C' with (isstrict);
|
||||
|
||||
--
|
||||
-- 7.2 GiST support functions
|
||||
--
|
||||
|
||||
CREATE FUNCTION ggeometry_consistent(internal,geometry,int4)
|
||||
RETURNS bool
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION ggeometry_compress(internal)
|
||||
RETURNS internal
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION gbox_penalty(internal,internal,internal)
|
||||
RETURNS internal
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION gbox_picksplit(internal, internal)
|
||||
RETURNS internal
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION gbox_union(bytea, internal)
|
||||
RETURNS internal
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION gbox_same(box, box, internal)
|
||||
RETURNS internal
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION rtree_decompress(internal)
|
||||
RETURNS internal
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
--
|
||||
-- 7.2 RTREE support functions
|
||||
--
|
||||
|
||||
CREATE FUNCTION geometry_union(geometry,geometry)
|
||||
RETURNS geometry
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION geometry_inter(geometry,geometry)
|
||||
RETURNS geometry
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
CREATE FUNCTION geometry_size(geometry,internal)
|
||||
RETURNS float4
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
--
|
||||
-- Create opclass index bindings
|
||||
--
|
||||
|
||||
CREATE OPERATOR CLASS gist_geometry_ops
|
||||
DEFAULT FOR TYPE geometry USING gist AS
|
||||
OPERATOR 1 << ,
|
||||
OPERATOR 2 &< ,
|
||||
OPERATOR 3 && ,
|
||||
OPERATOR 4 &> ,
|
||||
OPERATOR 5 >> ,
|
||||
OPERATOR 6 ~= ,
|
||||
OPERATOR 7 ~ ,
|
||||
OPERATOR 8 @ ,
|
||||
FUNCTION 1 ggeometry_consistent (internal, geometry, int4),
|
||||
FUNCTION 2 gbox_union (bytea, internal),
|
||||
FUNCTION 3 ggeometry_compress (internal),
|
||||
FUNCTION 4 rtree_decompress (internal),
|
||||
FUNCTION 5 gbox_penalty (internal, internal, internal),
|
||||
FUNCTION 6 gbox_picksplit (internal, internal),
|
||||
FUNCTION 7 gbox_same (box, box, internal);
|
||||
|
||||
UPDATE pg_opclass
|
||||
SET opckeytype = (select oid from pg_type where typname = 'box')
|
||||
WHERE opcname = 'gist_geometry_ops';
|
||||
|
||||
CREATE OPERATOR CLASS btree_geometry_ops
|
||||
DEFAULT FOR TYPE geometry USING btree AS
|
||||
OPERATOR 1 < ,
|
||||
OPERATOR 2 <= ,
|
||||
OPERATOR 3 = ,
|
||||
OPERATOR 4 >= ,
|
||||
OPERATOR 5 > ,
|
||||
FUNCTION 1 geometry_cmp (geometry, geometry);
|
||||
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- FIX_GEOMETRY_COLUMNS()
|
||||
--
|
||||
-- Since 7.3 schema support has been added.
|
||||
-- Previous postgis versions used to put the database name in
|
||||
-- the schema column. This needs to be fixed, so we set to the
|
||||
-- empty string any schema value not existing in pg_namespace
|
||||
--
|
||||
|
||||
CREATE FUNCTION fix_geometry_columns() RETURNS text
|
||||
AS
|
||||
'
|
||||
BEGIN
|
||||
-- it would be better to find the correct schema name
|
||||
UPDATE geometry_columns SET f_table_schema = ''public''
|
||||
WHERE f_table_schema is NULL or f_table_schema NOT IN
|
||||
( SELECT nspname::varchar FROM pg_namespace );
|
||||
|
||||
UPDATE geometry_columns SET attrelid = (
|
||||
SELECT c.oid
|
||||
FROM pg_class c, pg_attribute a, pg_namespace n
|
||||
WHERE c.relname = geometry_columns.f_table_name::name
|
||||
AND a.attrelid = c.oid AND c.relnamespace = n.oid
|
||||
AND a.attname = geometry_columns.f_geometry_column::name
|
||||
AND n.nspname = geometry_columns.f_table_schema::name
|
||||
);
|
||||
|
||||
UPDATE geometry_columns SET varattnum = (
|
||||
SELECT a.attnum
|
||||
FROM pg_class c, pg_attribute a, pg_namespace n
|
||||
WHERE n.nspname = geometry_columns.f_table_schema::name
|
||||
AND c.relname = geometry_columns.f_table_name::name
|
||||
AND a.attname = geometry_columns.f_geometry_column::name
|
||||
AND a.attrelid = c.oid AND c.relnamespace = n.oid
|
||||
);
|
||||
|
||||
RETURN ''geometry_columns table is now linked to the system tables'';
|
||||
|
||||
|
||||
END;
|
||||
'
|
||||
LANGUAGE 'plpgsql' ;
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- ADDGEOMETRYCOLUMN (
|
||||
-- <catalog>, <schema>, <table name>, <column name>,
|
||||
-- <srid>, <type>, <dim> )
|
||||
--
|
||||
-- Type can be one of geometry, GEOMETRYCOLLECTION, POINT, MULTIPOINT, POLYGON,
|
||||
-- MULTIPOLYGON, LINESTRING, or MULTILINESTRING.
|
||||
--
|
||||
-- Types (except geometry) are checked for consistency using a CHECK constraint
|
||||
-- uses SQL ALTER TABLE command to add the geometry column to the table.
|
||||
-- Addes a row to geometry_columns.
|
||||
-- Addes a constraint on the table that all the geometries MUST have the same
|
||||
-- SRID. Checks the coord_dimension to make sure its between 0 and 3.
|
||||
-- Should also check the precision grid (future expansion).
|
||||
-- Calls fix_geometry_columns() at the end.
|
||||
--
|
||||
CREATE FUNCTION AddGeometryColumn(varchar,varchar,varchar,varchar,integer,varchar,integer)
|
||||
RETURNS text
|
||||
AS
|
||||
'
|
||||
DECLARE
|
||||
catalog_name alias for $1;
|
||||
schema_name alias for $2;
|
||||
table_name alias for $3;
|
||||
column_name alias for $4;
|
||||
new_srid alias for $5;
|
||||
new_type alias for $6;
|
||||
new_dim alias for $7;
|
||||
|
||||
rec RECORD;
|
||||
schema_ok bool;
|
||||
real_schema name;
|
||||
BEGIN
|
||||
|
||||
IF ( not ( (new_type =''GEOMETRY'') or
|
||||
(new_type =''GEOMETRYCOLLECTION'') or
|
||||
(new_type =''POINT'') or
|
||||
(new_type =''MULTIPOINT'') or
|
||||
(new_type =''POLYGON'') or
|
||||
(new_type =''MULTIPOLYGON'') or
|
||||
(new_type =''LINESTRING'') or
|
||||
(new_type =''MULTILINESTRING'')) )
|
||||
THEN
|
||||
RAISE EXCEPTION ''Invalid type name - valid ones are:
|
||||
GEOMETRY, GEOMETRYCOLLECTION, POINT,
|
||||
MULTIPOINT, POLYGON, MULTIPOLYGON,
|
||||
LINESTRING, or MULTILINESTRING '';
|
||||
RETURN ''fail'';
|
||||
END IF;
|
||||
|
||||
IF ( (new_dim >3) or (new_dim <0) ) THEN
|
||||
RAISE EXCEPTION ''invalid dimension'';
|
||||
RETURN ''fail'';
|
||||
END IF;
|
||||
|
||||
IF ( schema_name != '''' ) THEN
|
||||
schema_ok = ''f'';
|
||||
FOR rec IN SELECT nspname FROM pg_namespace WHERE text(nspname) = schema_name LOOP
|
||||
schema_ok := ''t'';
|
||||
END LOOP;
|
||||
|
||||
if ( schema_ok <> ''t'' ) THEN
|
||||
RAISE NOTICE ''Invalid schema name - using current_schema()'';
|
||||
SELECT current_schema() into real_schema;
|
||||
ELSE
|
||||
real_schema = schema_name;
|
||||
END IF;
|
||||
|
||||
ELSE
|
||||
SELECT current_schema() into real_schema;
|
||||
END IF;
|
||||
|
||||
EXECUTE ''ALTER TABLE '' || quote_ident(real_schema) ||
|
||||
''.'' || quote_ident(table_name) ||
|
||||
'' ADD COLUMN '' || quote_ident(column_name) ||
|
||||
'' geometry '';
|
||||
|
||||
EXECUTE ''ALTER TABLE '' || quote_ident(real_schema) ||
|
||||
''.'' || quote_ident(table_name) ||
|
||||
'' ADD CHECK (SRID('' || quote_ident(column_name) ||
|
||||
'') = '' || new_srid || '')'' ;
|
||||
|
||||
IF (not(new_type = ''GEOMETRY'')) THEN
|
||||
EXECUTE ''ALTER TABLE '' || quote_ident(real_schema) ||
|
||||
''.'' || quote_ident(table_name) ||
|
||||
'' ADD CHECK (geometrytype('' ||
|
||||
quote_ident(column_name) || '')='' ||
|
||||
quote_literal(new_type) || '' OR ('' ||
|
||||
quote_ident(column_name) || '') is null)'';
|
||||
END IF;
|
||||
|
||||
EXECUTE ''INSERT INTO geometry_columns VALUES ('' ||
|
||||
quote_literal('''') || '','' ||
|
||||
quote_literal(real_schema) || '','' ||
|
||||
quote_literal(table_name) || '','' ||
|
||||
quote_literal(column_name) || '','' ||
|
||||
new_dim || '','' || new_srid || '','' ||
|
||||
quote_literal(new_type) || '')'';
|
||||
|
||||
EXECUTE ''select fix_geometry_columns()'';
|
||||
--SELECT fix_geometry_columns();
|
||||
|
||||
return ''Geometry column '' || column_name || '' added to table ''
|
||||
|| real_schema || ''.'' || table_name || '' WITH a SRID of '' || new_srid ||
|
||||
'' and type '' || new_type;
|
||||
END;
|
||||
' LANGUAGE 'plpgsql' WITH (isstrict);
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- ADDGEOMETRYCOLUMN ( <schema>, <table>, <column>, <srid>, <type>, <dim> )
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
CREATE FUNCTION AddGeometryColumn(varchar,varchar,varchar,integer,varchar,integer) RETURNS text AS '
|
||||
DECLARE
|
||||
ret text;
|
||||
BEGIN
|
||||
SELECT AddGeometryColumn('''',$1,$2,$3,$4,$5,$6) into ret;
|
||||
RETURN ret;
|
||||
END;
|
||||
' LANGUAGE 'plpgsql' WITH (isstrict);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- DROPGEOMETRYCOLUMN( <schema name>, <table name>, <column name> )
|
||||
--
|
||||
-- Removes geometry column reference from geometry_columns table,
|
||||
-- and actually drops the column.
|
||||
--
|
||||
CREATE FUNCTION DropGeometryColumn(varchar,varchar,varchar)
|
||||
RETURNS text
|
||||
AS
|
||||
'
|
||||
DECLARE
|
||||
schema_name alias for $1;
|
||||
table_name alias for $2;
|
||||
column_name alias for $3;
|
||||
|
||||
myrec RECORD;
|
||||
real_schema name;
|
||||
okay boolean;
|
||||
query text;
|
||||
|
||||
BEGIN
|
||||
|
||||
|
||||
-- Find, check or fix schema_name
|
||||
IF ( schema_name != '''' ) THEN
|
||||
okay = ''f'';
|
||||
|
||||
FOR myrec IN SELECT nspname FROM pg_namespace WHERE text(nspname) = schema_name LOOP
|
||||
okay := ''t'';
|
||||
END LOOP;
|
||||
|
||||
IF ( okay <> ''t'' ) THEN
|
||||
RAISE NOTICE ''Invalid schema name - using current_schema()'';
|
||||
SELECT current_schema() into real_schema;
|
||||
ELSE
|
||||
real_schema = schema_name;
|
||||
END IF;
|
||||
ELSE
|
||||
SELECT current_schema() into real_schema;
|
||||
END IF;
|
||||
|
||||
-- first we find out if the column is in the geometry_columns table
|
||||
okay = ''f'';
|
||||
FOR myrec IN SELECT * from geometry_columns where f_table_schema = text(real_schema) and f_table_name = table_name and f_geometry_column = column_name LOOP
|
||||
okay := ''t'';
|
||||
END LOOP;
|
||||
IF (okay <> ''t'') THEN
|
||||
RAISE EXCEPTION ''column not found in geometry_columns table'';
|
||||
RETURN ''f'';
|
||||
END IF;
|
||||
|
||||
|
||||
-- Remove ref from geometry_columns table
|
||||
EXECUTE ''delete from geometry_columns where f_table_schema = '' ||
|
||||
quote_literal(real_schema) || '' and f_table_name = '' ||
|
||||
quote_literal(table_name) || '' and f_geometry_column = '' ||
|
||||
quote_literal(column_name);
|
||||
|
||||
-- Remove table column
|
||||
EXECUTE ''ALTER TABLE '' || quote_ident(real_schema) || ''.'' ||
|
||||
quote_ident(table_name) || '' DROP COLUMN '' ||
|
||||
quote_ident(column_name);
|
||||
|
||||
|
||||
RETURN real_schema || ''.'' || table_name || ''.'' || column_name ||'' effectively removed.'';
|
||||
|
||||
END;
|
||||
'
|
||||
LANGUAGE 'plpgsql' WITH (isstrict);
|
||||
|
||||
|
||||
|
||||
|
||||
END TRANSACTION;
|
|
@ -1,187 +0,0 @@
|
|||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
--
|
||||
-- $Id$
|
||||
--
|
||||
-- PostGIS - Spatial Types for PostgreSQL
|
||||
-- http://postgis.refractions.net
|
||||
-- Copyright 2001-2003 Refractions Research Inc.
|
||||
--
|
||||
-- This is free software; you can redistribute and/or modify it under
|
||||
-- the terms of hte GNU General Public Licence. See the COPYING file.
|
||||
--
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- $Log$
|
||||
-- Revision 1.2 2004/02/23 12:18:55 strk
|
||||
-- added skeleton functions for pg75 stats integration
|
||||
--
|
||||
-- Revision 1.1 2004/02/04 22:27:02 strk
|
||||
-- Added pg75 support scripts
|
||||
--
|
||||
-- Revision 1.2 2003/11/28 11:06:49 strk
|
||||
-- Added WKB_recv function for binary WKB input
|
||||
--
|
||||
-- Revision 1.1 2003/11/11 10:38:23 strk
|
||||
-- Postgresql 7.4 enabler scripts.
|
||||
--
|
||||
-- Revision 1.2 2003/07/01 18:30:55 pramsey
|
||||
-- Added CVS revision headers.
|
||||
--
|
||||
--
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
-- You might have to define the PL/PgSQL language usually done with the
|
||||
-- changelang script.
|
||||
|
||||
-- Here's some hokey code to test to see if PL/PgSQL is installed
|
||||
-- if it is, you get a message "PL/PgSQL is installed"
|
||||
-- otherwise it will give a big error message.
|
||||
|
||||
--CREATE FUNCTION plpgsql_call_handler() RETURNS language_handler AS
|
||||
-- '$libdir/plpgsql' LANGUAGE C;
|
||||
|
||||
--CREATE TRUSTED PROCEDURAL LANGUAGE plpgsql
|
||||
-- HANDLER plpgsql_call_handler;
|
||||
|
||||
--(select 'PL/PgSQL is installed.' as message from pg_language where lanname='plpgsql') union (select 'You must install PL/PgSQL before running this SQL file,\nor you will get an error. To install PL/PgSQL run:\n\tcreatelang plpgsql <dbname>'::text as message) order by message limit 1;
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- HISTOGRAM2D
|
||||
|
||||
CREATE FUNCTION histogram2d_in(cstring)
|
||||
RETURNS histogram2d
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION histogram2d_out(histogram2d)
|
||||
RETURNS cstring
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE histogram2d (
|
||||
alignment = double,
|
||||
internallength = variable,
|
||||
input = histogram2d_in,
|
||||
output = histogram2d_out,
|
||||
storage = main
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- BOX3D
|
||||
|
||||
CREATE FUNCTION box3d_in(cstring)
|
||||
RETURNS box3d
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION box3d_out(box3d)
|
||||
RETURNS cstring
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE box3d (
|
||||
alignment = double,
|
||||
internallength = 48,
|
||||
input = box3d_in,
|
||||
output = box3d_out
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- SPHEROID
|
||||
|
||||
CREATE FUNCTION spheroid_in(cstring)
|
||||
RETURNS spheroid
|
||||
AS '@MODULE_FILENAME@','ellipsoid_in'
|
||||
LANGUAGE 'C' WITH (isstrict,iscachable);
|
||||
|
||||
CREATE FUNCTION spheroid_out(spheroid)
|
||||
RETURNS cstring
|
||||
AS '@MODULE_FILENAME@','ellipsoid_out'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE spheroid (
|
||||
alignment = double,
|
||||
internallength = 65,
|
||||
input = spheroid_in,
|
||||
output = spheroid_out
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- WKB
|
||||
|
||||
CREATE FUNCTION wkb_in(cstring)
|
||||
RETURNS wkb
|
||||
AS '@MODULE_FILENAME@','WKB_in'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION wkb_out(wkb)
|
||||
RETURNS cstring
|
||||
AS '@MODULE_FILENAME@','WKB_out'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION wkb_recv(internal)
|
||||
RETURNS wkb
|
||||
AS '@MODULE_FILENAME@','WKB_recv'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- CHIP
|
||||
|
||||
CREATE FUNCTION chip_in(cstring)
|
||||
RETURNS chip
|
||||
AS '@MODULE_FILENAME@','CHIP_in'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION chip_out(chip)
|
||||
RETURNS cstring
|
||||
AS '@MODULE_FILENAME@','CHIP_out'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE chip (
|
||||
alignment = double,
|
||||
internallength = variable,
|
||||
input = chip_in,
|
||||
output = chip_out,
|
||||
storage = extended
|
||||
);
|
||||
|
||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
-- GEOMETRY
|
||||
|
||||
CREATE FUNCTION geometry_in(cstring)
|
||||
RETURNS geometry
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION geometry_out(geometry)
|
||||
RETURNS cstring
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE FUNCTION geometry_analyze(internal)
|
||||
RETURNS bool
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE TYPE geometry (
|
||||
alignment = double,
|
||||
internallength = variable,
|
||||
input = geometry_in,
|
||||
output = geometry_out,
|
||||
storage = main,
|
||||
analyze = geometry_analyze
|
||||
);
|
||||
|
||||
--
|
||||
-- GiST selectivity function
|
||||
--
|
||||
|
||||
CREATE FUNCTION postgis_gist_sel (internal, oid, internal, int4)
|
||||
RETURNS float8
|
||||
AS '@MODULE_FILENAME@'
|
||||
LANGUAGE 'C';
|
||||
|
||||
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue