postgresql7.1
select case when i.storage_type = 'file'
then '[cr_fs_path]' || r.content
when i.storage_type = 'lob'
then lob::text
else r.content end as content, i.storage_type
from cr_revisions r, cr_items i
where r.item_id = i.item_id and r.revision_id = $revision_id
select
distinct i.item_id, i.live_revision
from
cr_items i, cr_release_periods p
where
i.publish_status = 'ready'
and
i.live_revision is not null
and
i.item_id = p.item_id
and
(current_timestamp between p.start_when and p.end_when)
select
distinct i.item_id
from
cr_items i, cr_release_periods p
where
i.publish_status = 'live'
and
i.live_revision is not null
and
i.item_id = p.item_id
and
not exists (select 1 from cr_release_periods p2
where p2.item_id = i.item_id
and (current_timestamp between p2.start_when and p2.end_when)
)