Postgresql 参数不会传递给函数中的函数

Postgresql 参数不会传递给函数中的函数,postgresql,Postgresql,我正在使用postgres函数创建交叉表 我的第一个动态查询函数(dynamic_crosstab)创建一个sql select语句,然后这个select语句给出执行时的最终结果。 动态交叉表函数可以完美地工作 我需要使用参数执行这个select查询(dynamic_crosstab函数的结果),所以我再次使用函数 CREATE OR REPLACE FUNCTION primary_cross( date, date, integer) RETURNS text A

我正在使用postgres函数创建交叉表

我的第一个动态查询函数(dynamic_crosstab)创建一个sql select语句,然后这个select语句给出执行时的最终结果。 动态交叉表函数可以完美地工作

我需要使用参数执行这个select查询(dynamic_crosstab函数的结果),所以我再次使用函数

CREATE OR REPLACE FUNCTION primary_cross(
    date,
    date,
    integer)
  RETURNS text AS
$BODY$
declare
val_1 text;
begin
select * from dynamic_crosstab('select 
        p.location_id, p.employee_id, pt.description, sum(p.hours_allocated) as hours_allocated
    from
        preference_type pt, preference p, preference_date_etl pde, date_etl de
    where
        pt.id = p.preference_type_id and
        pde.preference_id = p.id and
        pde.corporation_id = $3 and
        de.id = pde.date_etl_id and
        pde.deleted = ''''N'''' and
        p.deleted = ''''N'''' and
        pt.deleted = ''''N'''' and
        de.local_date between ''''$1'''' and ''''$2'''' and
        p.employee_id IN (
            select id from employee where user_id IN (select id from app_user where corporation_id = $3))
    group by p.location_id, p.employee_id, pt.description',
'select distinct description from preference_type where corporation_id =$3',
'text','location_id int , employee_id int',false) INTO val_1;
return val_1;
end;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
请注意,dynamic_crosstab函数使用4个输入参数。2个sql查询、2个文本值和一个布尔值

现在的问题是,参数被正确地传递到dynamic_crosstab函数的第一个输入,但它们没有传递到dynamic_crosstab函数的第二个输入,即:

'select distinct description from preference_type where deleted=''''N'''' and corporation_id =$3'
我得到以下错误:

ERROR:  there is no parameter $3
LINE 1: ...ct description from preference_type where corporation_id =$3
                                                                     ^
QUERY:  select distinct description from preference_type where corporation_id =$3
请告知我如何使用这些参数使其工作

多谢各位