에 경로에 rcost를 사용하는 것과 내가 외부 경로 내 네트워크에서 PostgreSQL의 전화를 pyscripter를 사용하고, 나는 을 사용하려는 경우 여기에 내 코드,파이썬 오류 PostgreSQL을
import sys, os
#set up psycopg2 environment
import psycopg2
#driving_distance module
query = """
select *
from driving_distance ($$
select
gid as id,
source::int4 as source,
target::int4 as target,
cost::double precision as cost
from network
$$, %s, %s, %s, %s
)
"""
#make connection between python and postgresql
conn = psycopg2.connect("dbname = 'TC_area' user = 'postgres' host = 'localhost' password = 'xxxx'")
cur = conn.cursor()
#count rows in the table
cur.execute("select count(*) from network")
result = cur.fetchone()
k = result[0] + 1 #number of points = number of segments + 1
#run loops
rs = []
i = 1
while i <= k:
cur.execute(query, (i, 1000000, False, True))
rs.append(cur.fetchall())
i = i + 1
#import csv module
import csv
j = 0
h = 0
ars = []
element = list(rs)
#export data to every row
with open('distMatrix.csv', 'wb') as f:
writer = csv.writer(f, delimiter = ',')
while j <= k - 1:
while h <= k - 1:
rp = element[j][h][1]
ars.append(rp)
h = h + 1
else:
h = 0
writer.writerow(ars)
ars = []
j = j + 1
conn.close()
결과는 좋은입니다 만, , 난 그냥 '비용과 같은 비용 : 배정 밀도'아래에 한 줄을 추가, PostgreSQL의에서 함수 driving_distance에 기능을 reverse_cost
rcost::double precision as reverse_cost
나는 내가이 리터를 추가 한 후이 오류 상자가 튀어 있어요 오프라인,
및 파이썬 IDLE에서 오류 메시지
Traceback (most recent call last):
File "C:\Users\Heinz\Documents\pyscript\postgresql\distMatrix.py.py", line 47, in <module>
cur.execute(query, (i, 1000000, False, True))
ProgrammingError: 錯誤: 在"語法錯誤"附近發生 rcost
LINE 7: rcost::double precision as reverse_cost
^
QUERY:
select
gid as id,
source::int4 as source,
target::int4 as target,
cost::double precision as cost
rcost::double precision as reverse_cost
from network
PS. 내가 pgAdmin 내부의 코드를 실행하면 나는 성공적으로 권리를 얻을 수,
, 따라서 그것은보기의 일부입니다 여기에 'rcost'열을 가지고, 그리고이 네트워크의 테이블을 변경 한 그 결과,
SELECT * FROM driving_distance('
SELECT gid as id,
source::int4 AS source,
target::int4 AS target,
cost::double precision as cost,
rcost::double precision as reverse_cost
FROM network',
3, 10000000, false, True);
하지만 나는이 문제를 해결할 수있는 방법, 루프를 할 파이썬을해야합니까?
PS. 내가 FALSE로 기능을 모두 부울을 설정하면, 이론적으로 프로그램은 rcost 무시하고 비용 만 계산 답변을 반환하지만, 난 여전히 같은 오류,
문제는 rcost 결과를 보인다있어 것.
저는 Windows 8.1 x64에서 PostgreSQL 8.4, Python 2.7.6을 사용하고 있습니다.
업데이트 # 1
나는 내 스크립트에 2 개 라인을 변경하고 나서이 작품
cost::double precision as cost, #need to add a trailing comma if followed by rcost
cur.execute(query, (i, 100000000000, False, True)) #the range must be greater than max of rcost
나를 상기시켜 주셔서 감사 드리며, 내 게시물을 편집했습니다. – Heinz