问题
So, I've got some generic data in a file. My quest is simple: store that in a field in the database, and retrieve it again later back in to a file. I don't care how it is stored, nor what methods used to transfer it back and forth (but if i can contain it to a plpgsql
function or two, that would be an awesome bonus). But it must come back to a file exactly the same as it was entered, bit for bit. I cannot guarantee that it wouldn't contain any special characters, and the data varies in size from a few KB to a few MB.
I've been trying with COPY
, lo_import
and lo_export
, pg_read_file
(etc) and every time, the resulting file is missing certain characters (encoding issues?) or is a different representation of what may be the same file (\000\014 etc from bytea) or is practically garbage. I'm comparing the input/output in notepad++ and also running the output each time but to no avail.
There's PHP, C++(+boost[speaking of which, i tried binarystring
s too...]) and this database sharing a 'working directory' that i've been using to transfer certain things between programs so any of these could do the job if necesary, but, as mentioned above, i'd like to use a plpgsql function or two if possible.
Also, please explain and example the solution like you're talking to an idiot. I certainly feel like one after having this problem for too long.
Thank you loads in advance, you will be solving much headache.
来源:https://stackoverflow.com/questions/31081736/transfering-raw-data-to-and-from-postgresql-database