-
Notifications
You must be signed in to change notification settings - Fork 54
TransposeDbUsageExample
Vasily i. Redkin edited this page Feb 13, 2015
·
2 revisions
Diff: https://github.com/vir/yate/commit/254ea98839d366c475e4b0a77cd22112a9cb8a6b
register.conf:
[call.route]
query=SELECT * FROM forking_route('${called}');
result=location
priority=90
namevaluepairs=yes
Routing function example (requires HSTORE postgresql extension):
CREATE OR REPLACE FUNCTION forking_route(called_arg TEXT) RETURNS TABLE(key TEXT, value TEXT) AS $$
DECLARE
res HSTORE;
cntr INTEGER;
BEGIN
.......
res := 'location => fork';
cntr := 0;
FOR t IN SELECT * FROM .......... LOOP
cntr := cntr + 1;
res := res || hstore('callto.' || cntr, t.location);
FOR kvp IN SELECT * FROM EACH(t.route_params) LOOP
res := res || hstore('callto.' || cntr || '.' || kvp.key, kvp.value);
END LOOP;
END LOOP;
...
RETURN QUERY SELECT * FROM each(res);
END;
$$ LANGUAGE PlPgSQL;