我有一张这样结构的桌子......
the_geom 数据
geom1 data1+3000||data2+1000||data3+222
geom2 data1+500||data2+900||data3+22232
我想创建一个按用户请求返回记录的函数。
Example: for data2, retrieve geom1,1000 and geom2, 900
直到现在我创建了这个函数(见下文),它工作得很好,但我面临一个参数替换问题......(你可以看到我无法用 'data2' 替换 $1 ......但是是的,我可以使用 $1之后
regexp_matches(t::text, E'(data2[\+])([0-9]+)'::text)::text)[2]::integer
我的功能
create or replace function get_counts(taxa varchar(100))
returns setof record
as $$
SELECT t2.counter,t2.the_geom
FROM (
SELECT (regexp_matches(t.data::text, E'(data2[\+])([0-9]+)'::text)::text)[2]::integer as counter,the_geom
from (select the_geom,data from simple_inpn2 where data ~ $1::text) as t
) t2
$$
language sql;
SELECT get_counts('data2') will work **but we should be able to make this substitution**:
regexp_matches(t::text, E'($1... instead of E'(data2....
我认为它更多的是语法问题,因为函数执行没有错误,只是将 $1 解释为字符串并且没有给出结果。
提前致谢,