Table 名称作为可变参数
Table name as variable parameter
我在 pgadmin 中创建了一个函数
create or replace function get_source2(a text)
returns integer as
$$
declare
a text;
geom geometry;
begin
select get_source(geom)
from a;
end;
$$
language plpgsql;
我想输入一个 table 名字 我该怎么办?我试着喜欢这个
select get_source2('postgis.center')
但我得到:
ERROR: relation "a" does not exist LINE 2: from a help me
试试这个:
create or replace function get_source2(a text)
returns integer as
$$
declare
geom geometry;
begin
execute 'select get_source(geom) from '||quote_ident(a) into geom;
return geom;
end;
$$
language plpgsql;
我在 pgadmin 中创建了一个函数
create or replace function get_source2(a text)
returns integer as
$$
declare
a text;
geom geometry;
begin
select get_source(geom)
from a;
end;
$$
language plpgsql;
我想输入一个 table 名字 我该怎么办?我试着喜欢这个
select get_source2('postgis.center')
但我得到:
ERROR: relation "a" does not exist LINE 2: from a help me
试试这个:
create or replace function get_source2(a text)
returns integer as
$$
declare
geom geometry;
begin
execute 'select get_source(geom) from '||quote_ident(a) into geom;
return geom;
end;
$$
language plpgsql;