title: PostgreSQL \lo_import and how to get the resulting OID into an UPDATE command?
body: <p>I'm working with Postgres 9.0, and I have an application where I need to insert images into the remote <code>server</code>. So I use:</p>
  
  <pre><code> "C:\Program Files\PostgreSQL\9.0\bin\psql.exe" -h 192.168.1.12 -p 5432 -d myDB -U my_admin -c  "\lo_import 'C://im/zzz4.jpg'";
  </code></pre>
  
  <p>where</p>
  
  <p><code>192.168.1.12</code> is the IP address of the server system</p>
  
  <p><code>5432</code> is the Port number</p>
  
  <p><code>myDB</code> is server database name</p>
  
  <p><code>my_admin</code> is the username</p>
  
  <p><code>"\lo_import 'C://im/zzz4.jpg'"</code> is the query that is fired.</p>
  
  <p><img src="https://i.stack.imgur.com/YxqXx.png" alt="Shell screenshot"></p>
  
  <p>After the image has been inserted into the database I need to update a row in a table like this:</p>
  
  <pre><code>UPDATE species 
  SET    speciesimages=17755;  -- OID from previous command.. how to get the OID ??
  WHERE  species='ACCOAA';
  </code></pre>
  
  <p>So my question is: how do I get the <code>OID</code> returned after the <code>\lo_import</code> in psql?</p>
  
  <p>I tried running <code>\lo_import 'C://im/zzz4.jpg'</code> in Postgres but I get an error:</p>
  
  <pre><code>ERROR:  syntax error at or near ""\lo_import 'C://im/zzz4.jpg'""
  LINE 1: "\lo_import 'C://im/zzz4.jpg'"
  </code></pre>
  
  <p>I <strong>also</strong> tried this:</p>
  
  <pre><code>update species
  set speciesimages=\lo_import 'C://im/zzz4.jpg'
  where species='ACAAC04';
  </code></pre>
  
  <p>But I get this error:</p>
  
  <pre><code>ERROR:  syntax error at or near "\"
  LINE 2: set speciesimages=\lo_import 'C://im/zzz4.jpg'
                            ^
  </code></pre>