Prepare routing table for Dijkstra

Add source, target and length column

ALTER TABLE victoria ADD COLUMN source integer;
ALTER TABLE victoria ADD COLUMN target integer;
ALTER TABLE victoria ADD COLUMN length double precision;

Create network topology

SELECT assign_vertex_id('victoria', 0.001, 'the_geom', 'gid');
UPDATE victoria SET length = length(the_geom);

Create indexes for source, target and geometry column

CREATE INDEX source_idx ON victoria(source);
CREATE INDEX target_idx ON victoria(target);
CREATE INDEX geom_idx ON victoria USING GIST(the_geom GIST_GEOMETRY_OPS);

Run Shortest Path Dijkstra query

shortest_path( sql text, 
		   source_id integer, 
		   target_id integer, 
		   directed boolean, 
		   has_reverse_cost boolean ) 

(Source and target IDs are node IDs.)

Shortest path core function

SELECT * FROM shortest_path('
		SELECT gid as id, 
			 source::integer, 
			 target::integer, 
			 length::double precision as cost 
			FROM victoria', 
		238, 1455, false, false); 
 vertex_id | edge_id |       cost       
-----------+---------+------------------
       238 |   76619 | 172.172139617447
      1051 |   80792 | 309.209732132692
       632 |   22142 | 275.695065878201
       ... |     ... | ...

Wrapper function without bounding box

SELECT gid, AsText(the_geom) AS the_geom 
	FROM dijkstra_sp('victoria', 238, 1455);
  gid   |                              the_geom      
--------+---------------------------------------------------------------
    484 | MULTILINESTRING((-13735834.0196717 6151280.78177026, ... ))
  13944 | MULTILINESTRING((-13734179.5114759 6150720.27269911, ... ))
  22142 | MULTILINESTRING((-13733851.6421797 6149933.91231484, ... ))
    ... | ...

Wrapper function with bounding box

SELECT gid, AsText(the_geom) AS the_geom 
	FROM dijkstra_sp_delta('victoria', 238, 1455, 3000);