wriring a file to a database
Hello,
I want to write a file into a database from python using psycopg. I
have tried several ways to insert the file, each gives a different
error.
File "write_images_to_db.py", line 43, in insert
curs.execute("INSERT INTO diamonds VALUES (%s, lo_import
%s)",(iname, image))
psycopg2.ProgrammingError: type "lo_import" does not exist
curs.execute("INSERT INTO diamonds VALUES (%s, \lo_import
%s)",(iname, image))
psycopg2.ProgrammingError: syntax error at or near "\" at character 50
curs.execute("INSERT INTO diamonds VALUES (%s, lo_import
(%s))",(iname, image))
psycopg2.ProgrammingError: must be superuser to use server-side
lo_import()
HINT: Anyone can use the client-side lo_import() provided by libpq.
curs.execute("INSERT INTO diamonds VALUES (%s,
\lo_import(%s))",(iname, image))
psycopg2.ProgrammingError: syntax error at or near "\" at character 50
Can someone please help out?
Thanks,
Roger
Postgresql 8.0.9 on Gentoo Linux
On Sat, 8 Dec 2007, Roger Mason wrote:
I want to write a file into a database from python using psycopg.
You don't use lo_import directly for that. There is an example program
included with psycopg that shows the right syntax to insert a file. For
psycopg1, see bytea.py ; for psycopg2 look at binary.py
curs.execute("INSERT INTO diamonds VALUES (%s,
\lo_import(%s))",(iname, image))
psycopg2.ProgrammingError: syntax error at or near "\" at character 50
Just so you know, the commands starting with \ like \lo_import are
specific to the psql client. None of those will work if you use another
tool to connect.
--
* Greg Smith gsmith@gregsmith.com http://www.gregsmith.com Baltimore, MD