0

Here is my code:

    currSrc = connSrc.cursor()
    currSrc.execute("""SELECT request_id, time_beg, shape FROM "REQUESTS" WHERE fl_ready=1""")

shape have type blob (bytea). I need to save it's on FS. How can I do it with Python?

3
  • 1
    Take a look at the link I posted, there should be no difference between PostgreSQL and MySQL blob handling. Commented May 25, 2016 at 12:01
  • @Erik The answer to that question was a quick fix for a problem caused by a bad design decision which was to save a binary file in a bytea column as a base64 encoded string, not as binary as it should be. Commented May 25, 2016 at 13:25
  • I strongly recommend against saving files inside the database, since it leads to fast database size growth and consequently to database slowness. Commented May 25, 2016 at 16:56

1 Answer 1

0

Just write it to the disk:

currSrc.execute("""
    SELECT request_id, time_beg, shape
    FROM "REQUESTS"
    WHERE fl_ready=1
""")
rs = cursor.fetchall()
f = open('/path/to/the/file', 'wb')
f.write(rs[0][2])
f.close()

The reason for the [0][2] is that it is the first line of the result set and the third column.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.