Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select c.data into data from doc c where c.doc_id = id and c.group_cur > group_cur order by c.id desc limit 1;
- EXCEPTION
- WHEN NO_DATA_FOUND THEN
- select c.data into data from doc c where c.doc_id = id and c.global_cur > global_cur order by c.id desc limit 1;
- EXCEPTION
- WHEN NO_DATA_FOUND THEN
- RETURN NULL;
- SELECT c.data into data
- FROM doc c
- WHERE c.doc_id = id
- and (
- c.group_cur > group_cur
- or
- c.global_cur > global_cur
- )
- ORDER BY
- -- this will make group always preferred over global
- case when c.group_cur > group_cur then 1 else 2 end ASC,
- -- and this is your normal ordering
- c.id DESC
- limit 1;
- select c.data into data
- from doc c
- where c.doc_id = id and c.group_cur > group_cur
- order by c.id desc limit 1;
- if not found then
- select c.data into data
- from doc c
- where c.doc_id = id and c.global_cur > global_cur
- order by c.id desc limit 1;
- if not found then return null; end if;
- end if;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement