Reputation: 493
What's wrong with these statements.
It keeps telling me 'ERROR: syntax error at or near "FOR"'
BEGIN
FOR foo in select id from tbl_number where error_msg = 'FAIL' and log_time::date between '2014-05-31' and '2014-05-31'
LOOP
select * from tbl_number
where id = foo.id
order by log_time desc limit 1;
END LOOP;
END
Upvotes: 0
Views: 75
Reputation: 125284
You don't need that loop
select distinct on (id) *
from tbl_number
where
error_msg = 'FAIL'
and
log_time::date between '2014-05-31' and '2014-05-31'
order by id, log_time desc;
Upvotes: 1