Home Explore Blog CI



postgresql

8th chunk of `doc/src/sgml/lobj.sgml`
876d85dd9b36e9da1e2bbde78a3f2aeeff71bc3f76ac9c2c0000000100000fa5
 object from the database, call
<synopsis>
int lo_unlink(PGconn *conn, Oid lobjId);
</synopsis>
     The <parameter>lobjId</parameter> argument specifies the OID of the
     large object to remove.  Returns 1 if successful, -1 on failure.
    </para>
   </sect2>

</sect1>

<sect1 id="lo-funcs">
<title>Server-Side Functions</title>

  <para>
   Server-side functions tailored for manipulating large objects from SQL are
   listed in <xref linkend="lo-funcs-table"/>.
  </para>

   <table id="lo-funcs-table">
    <title>SQL-Oriented Large Object Functions</title>
    <tgroup cols="1">
     <thead>
      <row>
       <entry role="func_table_entry"><para role="func_signature">
        Function
       </para>
       <para>
        Description
       </para>
       <para>
        Example(s)
       </para></entry>
      </row>
     </thead>

     <tbody>
      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>lo_from_bytea</primary>
        </indexterm>
        <function>lo_from_bytea</function> ( <parameter>loid</parameter> <type>oid</type>, <parameter>data</parameter> <type>bytea</type> )
        <returnvalue>oid</returnvalue>
       </para>
       <para>
        Creates a large object and stores <parameter>data</parameter> in it.
        If <parameter>loid</parameter> is zero then the system will choose a
        free OID, otherwise that OID is used (with an error if some large
        object already has that OID).  On success, the large object's OID is
        returned.
       </para>
       <para>
        <literal>lo_from_bytea(0, '\xffffff00')</literal>
        <returnvalue>24528</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>lo_put</primary>
        </indexterm>
        <function>lo_put</function> ( <parameter>loid</parameter> <type>oid</type>, <parameter>offset</parameter> <type>bigint</type>, <parameter>data</parameter> <type>bytea</type> )
        <returnvalue>void</returnvalue>
       </para>
       <para>
        Writes <parameter>data</parameter> starting at the given offset within
        the large object; the large object is enlarged if necessary.
       </para>
       <para>
        <literal>lo_put(24528, 1, '\xaa')</literal>
        <returnvalue></returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>lo_get</primary>
        </indexterm>
        <function>lo_get</function> ( <parameter>loid</parameter> <type>oid</type> <optional>, <parameter>offset</parameter> <type>bigint</type>, <parameter>length</parameter> <type>integer</type> </optional> )
        <returnvalue>bytea</returnvalue>
       </para>
       <para>
        Extracts the large object's contents, or a substring thereof.
       </para>
       <para>
        <literal>lo_get(24528, 0, 3)</literal>
        <returnvalue>\xffaaff</returnvalue>
       </para></entry>
      </row>
     </tbody>
    </tgroup>
   </table>

  <para>
   There are additional server-side functions corresponding to each of the
   client-side functions described earlier; indeed, for the most part the
   client-side functions are simply interfaces to the equivalent server-side
   functions.  The ones just as convenient to call via SQL commands are
   <function>lo_creat</function><indexterm><primary>lo_creat</primary></indexterm>,
   <function>lo_create</function>,
   <function>lo_unlink</function><indexterm><primary>lo_unlink</primary></indexterm>,
   <function>lo_import</function><indexterm><primary>lo_import</primary></indexterm>, and
   <function>lo_export</function><indexterm><primary>lo_export</primary></indexterm>.
   Here are examples of their use:

<programlisting>
CREATE TABLE image (
    name            text,
    raster          oid
);

SELECT lo_creat(-1);       -- returns OID of new, empty large

Title: PostgreSQL Server-Side Large Object Functions
Summary
This section describes PostgreSQL server-side functions for manipulating large objects, including creating, writing to, reading from, and removing large objects, with examples and function signatures for various functions such as lo_from_bytea, lo_put, lo_get, lo_creat, lo_unlink, lo_import, and lo_export, and how to use them via SQL commands.