Posted By

arunpjohny on 01/16/12


Tagged

postgres


Versions (?)

Convert OID to Bytea


 / Published in: SQL
 

Convert an oid value into a bytea value.

  1. CREATE OR REPLACE FUNCTION merge_oid(val oid)
  2. returns bytea AS $$
  3. declare merged bytea;
  4. declare arr bytea;
  5. BEGIN
  6. FOR arr IN SELECT DATA FROM pg_largeobject WHERE loid = val ORDER BY pageno LOOP
  7. IF merged IS NULL THEN
  8. merged := arr;
  9. ELSE
  10. merged := merged || arr;
  11. END IF;
  12. END LOOP;
  13. RETURN merged;
  14.  
  15. END
  16. $$ LANGUAGE plpgsql;

Report this snippet  

You need to login to post a comment.