I have installed pgRouting and whenever I create a new database in PostgreSQL, and in order to use the pgRouting function, I have to execute 3 sql files of pgRouting,
- routing_core
- routing_core_wrappers
- routing_core_wrappers
Can I use the pgRouting function just after I create a database without executing its sql files every time? How?
I am using PostgreSQL 8.4 under Windows 8.1 x64, thank you.
UPDATE#1
I have installed PostgreSQL 9.2 and create a database named "test", loading a shapefile in it, but as I execute the sql line below, the error message shows that the python can't find the 9.2 server,
import sys
import psycopg2
conn = psycopg2.connect("dbname = 'test' user = 'postgres' host = 'localhost' password = 'ntubse40'")
cur = conn.cursor()
query = """
ALTER TABLE tc_2000_w_area ADD COLUMN source integer;
ALTER TABLE tc_2000_w_area ADD COLUMN target integer;
SELECT assign_vertex_id('tc_2000_w_area', 0.0001, 'the_geom', 'gid')
;"""
cur.execute(query)
#print out table and check its change
cur.copy_to(sys.stdout, 'tc_2000_w_area', sep = '|')
cur.close()
>>>
Traceback (most recent call last):
File "C:/Users/Heinz/Desktop/python_test/any_test.py", line 4, in <module>
conn = psycopg2.connect("dbname = 'test' user = 'postgres' host = 'localhost' password = 'ntubse40'")
File "C:\Python27\lib\site-packages\psycopg2\__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
OperationalError: 嚴重錯誤: 資料庫"test"不存在
UPDATE#2 I finally solve the change server problem (just a stupid one, thanks Craig Ringer!), and I try the following code, successfully connect to 9.2 server,
import sys
import psycopg2
conn = psycopg2.connect("port = '5433' dbname = 'test' user = 'postgres' host = 'localhost' password = 'xxxx'")
cur = conn.cursor()
query = """
ALTER TABLE tc_2000_w_area ADD COLUMN source integer;
ALTER TABLE tc_2000_w_area ADD COLUMN target integer;
SELECT assign_vertex_id('tc_2000_w_area', 0.0001, 'the_geom', 'gid')
;"""
cur.execute(query)
#print out table and check its change
cur.copy_to(sys.stdout, 'tc_2000_w_area', sep = '|')
cur.close()