Diskuse:PgRouting
Poznámky
Funkce assign_vertex_id() pro non-public schéma
Funkce assign_vertex_id() předpokládá, že tabulka se kterou pracuje se nachází ve schématu 'public'. Následující patch přidá do této funkce nových argument pro definici pracovního schématu.
--- pgrouting/routing_topology.sql 2012-05-02 11:41:50.000000000 +0200
+++ routing_topology.sql 2012-05-02 15:32:46.000000000 +0200
@@ -8,7 +8,7 @@
-- Last changes: 16.04.2008
-- Author: Christian Gonzalez
-----------------------------------------------------------------------
-CREATE OR REPLACE FUNCTION point_to_id(p geometry, tolerance double precision)
+CREATE OR REPLACE FUNCTION point_to_id(schema_name varchar, p geometry, tolerance double precision)
RETURNS BIGINT
AS
$$
@@ -20,7 +20,7 @@
BEGIN
- _srid := Find_SRID('public', 'vertices_tmp', 'the_geom');
+ _srid := Find_SRID(quote_ident(schema_name), 'vertices_tmp', 'the_geom');
SELECT
@@ -52,8 +52,8 @@
-- Last changes: 16.04.2008
-- Author: Christian Gonzalez
-----------------------------------------------------------------------
-
-CREATE OR REPLACE FUNCTION assign_vertex_id(geom_table varchar, tolerance double precision, geo_cname varchar, gid_cname varchar)
+CREATE OR REPLACE FUNCTION assign_vertex_id(schema_name varchar, geom_table varchar,
+ tolerance double precision, geo_cname varchar, gid_cname varchar)
RETURNS VARCHAR AS
$$
DECLARE
@@ -69,9 +69,9 @@
WHEN UNDEFINED_TABLE THEN
END;
- EXECUTE 'CREATE TABLE vertices_tmp (id serial)';
+ EXECUTE 'CREATE TABLE '||quote_ident(schema_name)||'.vertices_tmp (id serial)';
- srid := Find_SRID('public', quote_ident(geom_table), quote_ident(geo_cname));
+ srid := Find_SRID(quote_ident(schema_name), quote_ident(geom_table), quote_ident(geo_cname));
EXECUTE 'SELECT addGeometryColumn(''vertices_tmp'', ''the_geom'', '||srid||', ''POINT'', 2)';
@@ -80,13 +80,14 @@
FOR _r IN EXECUTE 'SELECT ' || quote_ident(gid_cname) || ' AS id,'
|| ' ST_StartPoint('|| quote_ident(geo_cname) ||') AS source,'
|| ' ST_EndPoint('|| quote_ident(geo_cname) ||') as target'
- || ' FROM ' || quote_ident(geom_table) || ' WHERE ' || quote_ident(geo_cname) || ' IS NOT NULL '
+ || ' FROM ' || quote_ident(schema_name) || '.' || quote_ident(geom_table)
+ || ' WHERE ' || quote_ident(geo_cname) || ' IS NOT NULL '
LOOP
- source_id := point_to_id(_r.source, tolerance);
- target_id := point_to_id(_r.target, tolerance);
+ source_id := point_to_id(schema_name, _r.source, tolerance);
+ target_id := point_to_id(schema_name, _r.target, tolerance);
- EXECUTE 'update ' || quote_ident(geom_table) ||
+ EXECUTE 'update ' || quote_ident(schema_name) || '.' || quote_ident(geom_table) ||
' SET source = ' || source_id ||
', target = ' || target_id ||
' WHERE ' || quote_ident(gid_cname) || ' = ' || _r.id;
@@ -98,3 +99,11 @@
$$
LANGUAGE 'plpgsql' VOLATILE STRICT;
+
+-- Overloaded for backward compatibility
+CREATE OR REPLACE FUNCTION assign_vertex_id(geom_table varchar, tolerance double precision, geo_cname varchar, gid_cname varchar)
+RETURNS VARCHAR AS
+$$
+ SELECT assign_vertex_id('public', $1, $2, $3, $4);
+$$
+LANGUAGE 'SQL' VOLATILE STRICT;