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

    Unanswered: Export PDF from table to PDF file

    Hello,

    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
    Posts
    2,988
    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: http://www.dbforums.com/misc.php?do=bbcode#code

    Tips for good questions:

    http://tkyte.blogspot.de/2005/06/how...questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html

  3. #3
    Join Date
    Oct 2017
    Posts
    2
    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
  •