This snippet is a part in a function takes an integer(and ID) and a string (a table name) as indata, referred to as $1 and $2. In the first example, as the function currently works, the input will be (68, 'heat_arcs') and the function works. However, the function needs to be expanded to work with different network types, so I figured I could change cost FROM heat_arcs' to cost FROM ' || $2 ||', but that produces a syntax error, due to "unterminated quoted string".
Why can I successfully join the string with the input data in the later part of the query, but not the early part? pgr_trsp asks for strings as input for both the first and the last parameter
Current:
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'
Desired:
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'
