-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trying to implement large object support #258
Comments
I'm not sure why this might happen, but I would try to gather more information:
What client LibPQ.jl version and what server version do you have? |
Thanks! With your suggestions, I was able to answer my own question. The verbose errors pointed to the right line in the libpq C code. |
For what it is worth, these functions perform basic large object import/export and deletion. function lo_import(conn::LibPQ.Connection, filename::AbstractString)::LibPQ.Oid
execute(conn, "BEGIN;");
res = 0
try
if (res = LibPQ.libpq_c.lo_import(conn.conn, filename)) == LibPQ.Oid(0x0)
@error LibPQ.error_message(conn)
end
finally
execute(conn,"COMMIT;")
end
res
end This export function creates a temporary file, writes the file to the temporary, hands function lo_export(func::Function, conn::LibPQ.Connection, oid::UInt32)
res = missing
filename=tempname(;cleanup=false)
try
execute(conn, "BEGIN;");
try
if LibPQ.libpq_c.lo_export(conn.conn, oid, filename) == 1
try
res = func(filename)
catch ex
@error ex
end
else
@error LibPQ.error_message(conn)
end
finally
execute(conn, "COMMIT;")
end
finally
rm(filename; force=true)
end
res
end The lo_unlink function doesn't seem to require a transaction. function lo_unlink(conn::LibPQ.Connection, oid::UInt32)
res = -1
if (res=LibPQ.libpq_c.lo_unlink(conn.conn, oid)) != 1
@error LibPQ.error_message(conn)
end
res
end |
I want to keep transactions out of the functions to allow users to decide on their transactions (e.g. maybe they want to do multiple operations within the transactions). But having functions that wrap the libpq_c code would definitely be useful, and this is helpful, thanks.
This is a good indication I should expose the verbosity option at the |
This question goes beyond the exported LibPQ functionality.
I'm trying to implement very simple large object support using a couple of the methods exposed in libpq_c.
Neither call to the libpq_c functions works.
The import function seems to get the correct filename to the library. But if I give it the name
of an existing file it fails with "ERROR: invalid large-object descriptor: 0"
Likewise the call to libpq_c.lo_export also fails with the same error message. ("ERROR: invalid large-object descriptor: 0")
Is there any reason you know why these functions will fail? The documentation mentions something about "pipeline mode" introduced in PostgreSQL 14 causing these functions to fail. But this has to be explicitly enabled.
The text was updated successfully, but these errors were encountered: