Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2017

    Unanswered: Export PDF from table to PDF file


    I have the following task. I need to export one column to files. The type of column is "text" yet it holds the binary data of various types of files. Most of them are ".txt" or ".pdf". Sporadically they are ".jpg". Is it possible? I read about a command like COPY (SELECT column FROM TABLE) to 'filename.txt' (FORMAT BINARY) or something like that.

    I also read that even with this command, which I actually executed, I would have to cut some bytes from the beginning of created files or in other words to process them somehow for them to show the content. The command above creates some pdf files but they are unable to show their contents in Adobe Acrobat Reader.

    Can somebody please tell me if it's possible?

  2. #2
    Join Date
    Nov 2003
    Provided Answers: 23
    That is not going to work.

    Storing binary data in a text column is always going to fail due to character set conversion applied to the data.

    You need to declare that column as bytea, otherwise you will never get the correct data in or out of the database.
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags:

    Tips for good questions:

  3. #3
    Join Date
    Oct 2017
    What about function "decode" which returns bytea from text. I copied the text to this function COPY (select decode ('text', 'base64')) to 'filepath' and still got no working pdf, but this time however the inside of the file looked like pdf.

    I guess there are wrongly decoded characters?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts