postgresql7.1
select forums_messages.*,
tree_level(forums_messages.tree_sortkey) as tree_level,
forums_message__root_message_id(forums_messages.message_id) as root_message_id,
(select subject from forums_messages
where message_id = forums_message__root_message_id(forums_messages.message_id)) as root_subject,
to_char(forums_messages.posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi
from forums_messages
where forums_messages.message_id= :message_id
select forums_messages.*,
(select count(*) from attachments where object_id= message_id) as n_attachments,
forums_message__root_message_id(forums_messages.message_id) as root_message_id,
(select subject from forums_messages
where message_id = forums_message__root_message_id(forums_messages.message_id)) as root_subject,
to_char(forums_messages.posting_date, 'YYYY-MM-DD HH24:MI:SS') as posting_date_ansi
from forums_messages
where forums_messages.message_id= :message_id
select forums_message__thread_close(:message_id);
select forums_message__thread_open(:message_id);