ERROR:  syntax error at or near "order"
LINE 1: ...|| ']' as etm from ewf.story_ a  WHERE a.sub_ctg= order by a...
                                                             ^

select a.id,a.title,substr(a.gist,1,400) as story,to_char(a.etm, 'FMDay,Month FMDD,IYYY') || ' [' || (select tmp.interval_time1(a.etm::text)) || ']' as etm from ewf.story_ a  WHERE a.sub_ctg= order by a.id desc OFFSET (1*7)-7  limit 7 

ERROR:  syntax error at or near ")"
LINE 1: ...in(select max(p_id) from ewf.story_pic where s_id=)) is null...
                                                             ^

SELECT case when (select pth from ewf.images where id in(select max(p_id) from ewf.story_pic where s_id=)) is null THEN (select pth from ewf.images where id=1803) else (select pth from ewf.images where id in(select max(p_id) from ewf.story_pic where s_id=))  end as path