【发布时间】:2017-10-17 04:06:25
【问题描述】:
这是我的第一个功能。使用固定常量手动执行选择查询时效果很好。但是在我的功能范围内,参数被错误地解释了。
基本上,我正在尝试用函数参数替换时间戳。
-- this my mananual query. it works fine.
select sum(least(end_time,'2017-05-16 11:30:00')- greatest(start_time,'2017-05-16 10:30:00')) as duration,
from c_trunk
where (start_time < '2017-05-16 11:30:00') and (end_time > '2017-05-16 10:30:00')
and trunk < 20
-- this is my bogus function with the select that calls it at the end.
create function trunk_trafficD (p1 timestamp, p2 timestamp)
returns boolean as $$
begin
select sum(least(end_time,p2)- greatest(start_time,p1)) as duration,
count(call_id), device as "system", trunk as "trunk"
from c_trunk
where (start_time < p2) and (end_time > p1)
and trunk < 20
and (device = 1 or device = 4 or device = 3)
return true;
end; $$
language PLPGSQL;
select trunk_trafficD('2017-05-16 10:30:00','2017-05-16 11:30:00');
【问题讨论】:
-
你的意思是
wrongly interpreted.?? -
顺便说一句,您可以使用
AND device IN (1,3,4)代替链接那些OR
标签: postgresql function parameters timestamp