我在 Greenplum postgres 中有如下定义的函数
CREATE OR REPLACE FUNCTION vin_temp_func(j text) RETURNS integer AS $$
Declare varx integer;
BEGIN
select count(*) into varx
from T_perf a
left join T_profile b on a.sr_number = b.sr_number where b.product_name like '%V1%' and
a.submit_date >= (('2013-02-01'::date - CAST(EXTRACT(DOW FROM '2013-02-01'::date) as int)) - 7)+'1 week'::interval and
a.submit_date <= ('2013-02-01'::date - CAST(EXTRACT(DOW FROM '2013-02-01'::date)+1 as int)) + '1 week'::interval+'23 hours'::interval+'59 minutes'::interval+'59 seconds'::interval
and b.product_name = j;
RETURN varx;
END;
$$ LANGUAGE plpgsql;
表定义如下
drop table if exists prod_week_A;
create table prod_week_A as (
select product_name
from T_profile where product_name like '%V1%' limit 100)
当我尝试执行以下操作时,出现错误“函数无法在段上执行,因为它访问关系”
select product_name, vin_temp_func(product_name)
from prod_week_A limit 100;
有人可以帮我解决这个问题吗?谢谢!