0
該片段是函數中的一部分,它將一個整數(和ID)和一個字符串(一個表名)作爲indata,稱爲$ 1和$ 2。在第一個示例中,由於當前的功能起作用,輸入將爲(68, 'heat_arcs')
並且該功能起作用。但是,該功能需要擴展以適應不同的表格,所以我想我可以將cost FROM heat_arcs'
更改爲cost FROM ' || $2 ||'
,但由於「未端接引用的字符串」,這會產生語法錯誤。使用管道連接字符串時的行爲不一致
爲什麼我可以在查詢的後面部分成功地將字符串與輸入數據連接起來,但不是在早期部分? pgr_trsp請求字符串作爲輸入的第一和最後一個參數
電流:
FROM pgr_trsp(
'SELECT gid as id, source, target, cost FROM heat_arcs',
r, 2, false, false, 'select 1000 as to_cost, b.target_id, a.via_path::text from
(select gid as target_id from '|| $2 ||' where source = ' || $1 ||' or target = ' || $1 ||') as b,
(select gid as via_path from '|| $2 ||' where source = ' || $1 ||' or target ='|| $1 ||') as a WHERE b.target_id <> a.via_path'
期望:
FROM pgr_trsp(
'SELECT gid as id, source, target, cost FROM '|| $2 ||',
r, 2, false, false, 'select 1000 as to_cost, b.target_id, a.via_path::text from
(select gid as target_id from '|| $2 ||' where source = ' || $1 ||' or target = ' || $1 ||') as b,
(select gid as via_path from '|| $2 ||' where source = ' || $1 ||' or target ='|| $1 ||') as a WHERE b.target_id <> a.via_path'
非常感謝,IMSoP。我也會接受你的建議,並檢查引用函數:) – FHilding