What is the 131072 in the call to lo_open() ByteA to BLOB conversions typically make a call to lo_open(),

CREATE OR REPLACE FUNCTION make_lo(bytea)
RETURNS oid AS $$
DECLARE
  loid oid;
  fd integer;
  bytes integer;
BEGIN
  loid := lo_creat(-1);
  fd := lo_open(loid, 131072); -- &lt;&lt;&lt; --==HERE==--
  bytes := lowrite(fd, $1);
  IF (bytes != LENGTH($1)) THEN
    RAISE EXCEPTION 'Not all data copied to blob';
  END IF;
  PERFORM lo_close(fd);
  RETURN loid;
END;
$$ LANGUAGE plpgsql STRICT;


In the above what is 

fd := lo_open(loid, 131072);


You can see others asking this same question here,


  The number 131072 is some flag I couldn't find what means, and 999999999 is the max read size, but I could read the value anyway.
This variable is called the "mode parameter" and it's the int representation of INV_READ (x'20000')

-- lo_open(lobjId oid, mode integer) returns integer
-- The mode parameter to lo_open uses two constants:
--   INV_READ  = 0x20000
--   INV_WRITE = 0x40000


You can see the integer representation like this,

SELECT CAST( x'20000' AS integer);
  int4  
--------
 131072
(1 row)


Personally, I would rather use x'20000' which I find to be more explicit. You can see INV_READ mentioned in a comment in largeobject.source, and you can see it defined it in the code at libpq-fs.h.

In the event you ever see 262144 that's the numified representation of INV_WRITE (0x40000).