I would try a user-defined function for this.
create table jobs (
id serial primary key,
job_status smallint not null default 1,
job_name text default 'FIXME',
inserted timestamptz default now()
);
insert into jobs ( job_status,inserted )
select case when random()<=0.05 then 0 else 1 end, localtimestamp
from generate_series(1,1000) x(x);
create or replace function get_jobs(p_limit int,p_offset int)
returns setof jobs as $$
declare
v_limit1 integer;
v_offset2 integer;
rec record;
begin
v_limit1 := p_limit - 1;
v_offset2 := p_offset / 20;
for rec in select * from jobs where job_status=1
order by inserted desc limit v_limit1 offset p_offset
loop
return next rec;
end loop;
return query select * from jobs where job_status=0 offset v_offset2 limit 1;
return;
end;
$$ language plpgsql;
This will list exactly one "inactive" job on last position of the page. The code might require some polishing, but you get the idea.
Hope this helps.
PS. @kurast: your solution does not work in PostgreSQL 8.4.1. It is not even syntactically correct. After correcting syntax, it does not work too. see below.
select * from(
select *, nextval('rownum1')*20 as myorder from jobs where job_status =0
union
select *, nextval('rownum2') as myorder from jobs where job_status =1
) subq
order by myorder desc;