每当有人请求新任务集(运行BIRT报告)时,我都希望从表中显示5个任务(行)。条件是,一旦显示任务,则在接下来的X秒内将无法再次显示相同的任务。
样本数据:
/*
-- drop table if exists task_list;
-- Create table for tasks
create table task_list (
id_task serial,
task_lock timestamp without time zone
);
-- Insert some tasks
insert into task_list select * from generate_series(1,100);
*/
为了实现所需的行为,我update
在CTE内部创建了查询:
with
tasks as (
update task_list set task_lock = Now()
where
id_task in (select id_task
from task_list
where task_lock is null
or task_lock < (Now() - interval '30 seconds') limit 5)
returning *
)
select * from tasks;
当我从pgAdmin重复运行查询时,此方法非常有效,但是当我将此查询添加到BIRT报表中时,此方法就无法正常工作。这在SQLFiddle中也不起作用。在这两个工具中,始终仅显示前5行。
为此,您必须将&AutoCommit
数据源的属性设置为true
可在BIRT Designer 4.2.2和相关的BIRT Viewer中使用
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句