Skip to content

Commit f18f8b5

Browse files
committed
Moving to legacy pgr_costResult type
Changes to be committed: * Moving to legacy the type modified: sql/common/pgrouting-types.sql modified: sql/legacy/routing_legacy.sql * Removing from the signature file modified: sql/sigs/pgrouting--3.0.0.sig * Not using the type on functions that still use it modified: sql/trsp/trsp_V2.2.sql modified: sql/tsp/tsp_v2.0_coordinates.sql modified: sql/vrppdtw/gsoc_vrppdtw.sql * Not using the type on C file modified: src/trsp/trsp.c
1 parent b274521 commit f18f8b5

8 files changed

Lines changed: 63 additions & 30 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6794-82c59e3 release/3.0
1+
6795-b274521 release/3.0

sql/common/pgrouting-types.sql

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2323

2424
-- pgRouting 2.0 types
2525

26-
CREATE TYPE pgr_costResult AS
27-
(
28-
seq integer,
29-
id1 integer,
30-
id2 integer,
31-
cost float8
32-
);
3326

3427
CREATE TYPE pgr_costResult3 AS
3528
(

sql/legacy/routing_legacy.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2424
2525
********************************************************************PGR-GNU*/
2626

27+
CREATE TYPE pgr_costResult AS
28+
(
29+
seq integer,
30+
id1 integer,
31+
id2 integer,
32+
cost float8
33+
);
2734

2835

2936
CREATE TYPE pgr_geomResult AS

sql/sigs/pgrouting--3.0.0.sig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#VERSION pgrouting 3.0.0
22
#TYPES
3-
pgr_costresult
43
pgr_costresult3
54
#FUNCTIONS
65
pgr_alphashape(text,double precision)

sql/trsp/trsp_V2.2.sql

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@ CREATE OR REPLACE FUNCTION _pgr_trsp(
3838
target_pos float8,
3939
directed boolean,
4040
has_reverse_cost boolean,
41-
turn_restrict_sql text DEFAULT null)
42-
RETURNS SETOF pgr_costResult
41+
turn_restrict_sql text DEFAULT null,
42+
43+
OUT seq INTEGER,
44+
OUT id1 INTEGER,
45+
OUT id2 INTEGER,
46+
OUT cost FLOAT
47+
)
48+
RETURNS SETOF record
4349
AS '${MODULE_PATHNAME}', 'turn_restrict_shortest_path_edge'
4450
LANGUAGE 'c' IMMUTABLE;
4551

@@ -68,8 +74,14 @@ CREATE OR REPLACE FUNCTION pgr_trsp(
6874
end_vid INTEGER,
6975
directed BOOLEAN,
7076
has_rcost BOOLEAN,
71-
restrictions_sql TEXT DEFAULT NULL)
72-
RETURNS SETOF pgr_costResult AS
77+
restrictions_sql TEXT DEFAULT NULL,
78+
79+
OUT seq INTEGER,
80+
OUT id1 INTEGER,
81+
OUT id2 INTEGER,
82+
OUT cost FLOAT
83+
)
84+
RETURNS SETOF record AS
7385
$BODY$
7486
DECLARE
7587
has_reverse BOOLEAN;
@@ -94,7 +106,7 @@ BEGIN
94106

95107
IF (restrictions_sql IS NULL OR length(restrictions_sql) = 0) THEN
96108
-- no restrictions then its a dijkstra
97-
RETURN query SELECT a.seq - 1 AS seq, node::INTEGER AS id1, edge::INTEGER AS id2, cost
109+
RETURN query SELECT a.seq - 1 AS seq, node::INTEGER AS id1, edge::INTEGER AS id2, a.cost
98110
FROM pgr_dijkstra(new_sql, start_vid, end_vid, directed) a;
99111
RETURN;
100112
END IF;
@@ -113,7 +125,7 @@ BEGIN
113125

114126

115127
RETURN query
116-
SELECT (seq - 1)::INTEGER, a.node::INTEGER, a.edge::INTEGER, a.cost
128+
SELECT (a.seq - 1)::INTEGER, a.node::INTEGER, a.edge::INTEGER, a.cost
117129
FROM _pgr_trsp(new_sql, restrictions_query, start_vid, end_vid, directed) AS a;
118130
IF NOT FOUND THEN
119131
RAISE EXCEPTION 'Error computing path: Path Not Found';
@@ -197,8 +209,14 @@ CREATE OR REPLACE FUNCTION pgr_trsp(
197209
target_pos float8,
198210
directed boolean,
199211
has_reverse_cost boolean,
200-
turn_restrict_sql text DEFAULT null)
201-
RETURNS SETOF pgr_costResult AS
212+
turn_restrict_sql text DEFAULT null,
213+
214+
OUT seq INTEGER,
215+
OUT id1 INTEGER,
216+
OUT id2 INTEGER,
217+
OUT cost FLOAT
218+
)
219+
RETURNS SETOF record AS
202220
$BODY$
203221
DECLARE
204222
has_reverse BOOLEAN;

sql/tsp/tsp_v2.0_coordinates.sql

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
3131

3232

3333

34-
CREATE OR REPLACE FUNCTION pgr_tsp(sql text, start_id INTEGER, end_id INTEGER default (-1))
35-
returns setof pgr_costResult as
34+
CREATE OR REPLACE FUNCTION pgr_tsp(
35+
sql text, start_id INTEGER,
36+
end_id INTEGER default (-1),
37+
38+
OUT seq INTEGER,
39+
OUT id1 INTEGER,
40+
OUT id2 INTEGER,
41+
OUT cost FLOAT
42+
)
43+
returns setof record as
3644
$body$
3745
DECLARE
3846
table_sql TEXT;

sql/vrppdtw/gsoc_vrppdtw.sql

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
CREATE OR REPLACE FUNCTION pgr_gsoc_vrppdtw(
22
sql text,
33
vehicle_num INTEGER,
4-
capacity INTEGER
4+
capacity INTEGER,
5+
6+
OUT seq INTEGER,
7+
OUT id1 INTEGER,
8+
OUT id2 INTEGER,
9+
OUT cost FLOAT
510
)
6-
RETURNS SETOF pgr_costresult AS
11+
RETURNS SETOF record AS
712
$BODY$
813
DECLARE
914
has_reverse BOOLEAN;
1015
customers_sql TEXT;
1116
BEGIN
1217
RETURN query
13-
SELECT a.seq, vehicle_id::INTEGER AS id1, stop_id::INTEGER AS id2, departure_time AS cost
14-
FROM _pgr_gsoc_vrppdtw($1, $2, $3, 1, 30) AS a WHERE vehicle_id NOT IN (-2);
18+
SELECT a.seq, vehicle_id::INTEGER AS id1, stop_id::INTEGER AS id2, departure_time AS cost
19+
FROM _pgr_gsoc_vrppdtw($1, $2, $3, 1, 30) AS a WHERE vehicle_id NOT IN (-2);
1520
END
1621
$BODY$
1722
LANGUAGE plpgsql VOLATILE

src/trsp/trsp.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -820,19 +820,22 @@ turn_restrict_shortest_path_edge(PG_FUNCTION_ARGS) {
820820
#endif
821821

822822
// total number of tuples to be returned
823-
#if 1
824823
#if PGSQL_VERSION > 95
825824
funcctx->max_calls = path_count;
826825
#else
827826
funcctx->max_calls = (uint32_t)path_count;
828827
#endif
829-
#else
830-
funcctx->max_calls = path_count;
831-
#endif
832-
funcctx->user_fctx = path;
833828

834-
funcctx->tuple_desc =
835-
BlessTupleDesc(RelationNameGetTupleDesc("pgr_costResult"));
829+
funcctx->user_fctx = path;
830+
if (get_call_result_type(fcinfo, NULL, &tuple_desc)
831+
!= TYPEFUNC_COMPOSITE) {
832+
ereport(ERROR,
833+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
834+
errmsg("function returning record called in context "
835+
"that cannot accept type record")));
836+
}
837+
838+
funcctx->tuple_desc = tuple_desc;
836839

837840
MemoryContextSwitchTo(oldcontext);
838841
}

0 commit comments

Comments
 (0)