I am trying to call either a stored procedure or function defined in the PostgreSQL/PostGIS database and use it from the QGIS Query Builder. Neither work:
- the function returns a table that cannot be interpreted by the Query Builder
- the procedure, which returns a selection, fails when I call it using the
call
instruction
Both work well in DataGrip and query a tag from a tag
text-array column in the waypoints
table.
Here is the function:
create or replace function gwd(t text)
RETURNS TABLE (f_ogc_fid int, f_name text)
LANGUAGE plpgsql
AS $$
BEGIN
return query
SELECT ogc_fid,name::text
FROM gis.gps.waypoints
where tag @> STRING_TO_ARRAY(t, ',');
end;
$$
Here is the procedure which fails at the CALL
in QGIS' Query Builder:
create or replace procedure grw(T text)
LANGUAGE plpgsql
AS $$
BEGIN
SELECT *
FROM gis.gps.waypoints
where tag @> STRING_TO_ARRAY(T, ',');
end;
$$
Here is the error reported by QGis when I execute call grw('iron')
in the Query Builder:
An error occurred when executing the query.
The data provider said:
ERROR: syntax error at or near "grw"
LINE 1: SELECT * FROM "gps"."waypoints" WHERE call grw('iron') LIMIT...
When I call it without the CALL
, it does not work either:
An error occurred when executing the query.
The data provider said:
ERROR: grw(unknown) is a procedure
LINE 1: SELECT * FROM "gps"."waypoints" WHERE grw('iron') LIMIT 0
HINT: To call a procedure, use CALL.