postgresql7.1 select mail_job_id from ml_mail_jobs where state = 'active' and scheduled_date <= current_timestamp update ml_mail_jobs set state = 'started', execution_date = current_timestamp where mail_job_id = :mail_job_id select r.mime_type, r.title, r.content as filename from cr_revisions r where r.revision_id = :css_revision_id union select r.mime_type, r.title, r.content as filename from cr_items i, cr_revisions r where r.item_id = i.item_id and i.parent_id = :mail_job_id update ml_user_email_log set last_mail_date = current_timestamp where user_id = :user_id update ml_mail_jobs set state = 'finished', mails_sent = :mail_count, track_links_p = (select case when count(*) = 0 then FALSE else TRUE end from mail_link_mail_map m where mail_id = :mail_job_id) where mail_job_id = :mail_job_id insert into ml_bounce_log (mail_job_id, user_id, sending_time, bouncing_time) (select mail_job_id, user_id, send_date as sending_time, current_timestamp as bouncing_time from ml_email_log where mail_job_id = :job_id and user_id = :user_id)