Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7663479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:04:09+00:00 2026-05-31T14:04:09+00:00

I’m working with Postgres 9.0, and I have an application where I need to

  • 0

I’m working with Postgres 9.0, and I have an application where I need to insert images into the remote server. So I use:

 "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'";

where

192.168.1.12 is the IP address of the server system

5432 is the Port number

myDB is server database name

my_admin is the username

"\lo_import 'C://im/zzz4.jpg'" is the query that is fired.

Shell screenshot

After the image has been inserted into the database I need to update a row in a table like this:

UPDATE species 
SET    speciesimages=17755;  -- OID from previous command.. how to get the OID ??
WHERE  species='ACCOAA';

So my question is: how do I get the OID returned after the \lo_import in psql?

I tried running \lo_import 'C://im/zzz4.jpg' in Postgres but I get an error:

ERROR:  syntax error at or near ""\lo_import 'C://im/zzz4.jpg'""
LINE 1: "\lo_import 'C://im/zzz4.jpg'"

I also tried this:

update species
set speciesimages=\lo_import 'C://im/zzz4.jpg'
where species='ACAAC04';

But I get this error:

ERROR:  syntax error at or near "\"
LINE 2: set speciesimages=\lo_import 'C://im/zzz4.jpg'
                          ^
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:04:10+00:00Added an answer on May 31, 2026 at 2:04 pm

    As your file resides on your local machine and you want to import the blob to a remote server, you have two options:

    1) Transfer the file to the server and use the server-side function:

    UPDATE species
    SET    speciesimages = lo_import('/path/to/server-local/file/zzz4.jpg')
    WHERE  species = 'ACAAC04';
    

    2) Use the psql meta-command like you have it.

    But you cannot mix psql meta commands with SQL-commands, that’s impossible.
    Use the psql variable :LASTOID in an UPDATE command that you launch immediately after the \lo_import meta command in the same psql session:

    UPDATE species
    SET    speciesimages = :LASTOID
    WHERE  species = 'ACAAC04';
    

    To script that (works in Linux, I am not familiar with Windows shell scripting):

    echo "\lo_import '/path/to/my/file/zzz4.jpg' \\\\ UPDATE species SET speciesimages = :LASTOID WHERE  species = 'ACAAC04';" | \
    psql -h 192.168.1.12 -p 5432 -d myDB -U my_admin
    
    • \\ is the separator meta-command. You need to double the \, in a "" string, because the shell interprets one layer.
    • \ before the newline is just the line continuation in Linux shells.

    Alternative syntax (tested on Linux again):

    psql -h 192.168.1.12 -p 5432 -d myDB -U my_admin << EOF
    \lo_import '/path/to/my/file/zzz4.jpg'
    UPDATE species
    SET    speciesimages = :LASTOID
    WHERE  species = 'ACAAC04';
    EOF
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I have a bunch of posts stored in text files formatted in yaml/textile (from
I need to write an AS3 program to search for a certain keyword in
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.