2017-02-02 6 views
0

Comment passer un paramètre dans crosstab requête dans postgresql. S'il vous plaît se référer à la fonction ci-dessous postgresqlparamètres pass dans une requête crosstab postgres

create function sp_nextfollowup_count_byweek(_from timestamp without time zone,_to timestamp without time zone) 
returns table(userid integer,username character varying,day1 bigint,day2 bigint,day3 bigint,day4 bigint,day5 bigint,day6 bigint,day7 bigint)as 
$BODY$ 
BEGIN 
return query 
with cte as(
select * from crosstab($$ 
select follow_up_by,next_follow_up_date,count(*) from sales_enquiry_follow_up where next_follow_up_date between _from and _to 
group by follow_up_by,next_follow_up_date 
order by follow_up_by,next_follow_up_date$$,$$select date::timestamp without time zone 
from generate_series(
    _from, 
    _to, 
    '1 day'::interval 
) date$$) 
as(id integer, dd bigint,dd1 bigint,dd2 bigint,dd3 bigint,dd4 bigint,dd5 bigint,dd6 bigint) 
) 
select cte.id,u.username,cte.dd,cte.dd1,cte.dd2,cte.dd3,cte.dd4,cte.dd5,cte.dd6 from cte left join users u on cte.id=u.id; 

END; 
$BODY$ 
language plpgsql; 

Je reçois cette erreur column "_from" does not exist. Comment résoudre ce problème?

Répondre

3

Parce que l'argument de tableau croisé est juste chaîne que vous devez inclure les arguments directement:

$$ 
select follow_up_by,next_follow_up_date,count(*) from sales_enquiry_follow_up where next_follow_up_date between $$ || quote_literal(_from) || $$ and $$ || quote_literal(_to) || $$ 
group by follow_up_by,next_follow_up_date 
order by follow_up_by,next_follow_up_date$$ 
+0

thanx..it travaillé – Bipin

+0

vous remercie m'a beaucoup aidé :) – charmi