MySQL: Return the size of a blob

February 28th, 2008 by jason

Ok, lets say you have stored a file as a blob in a database (maybe its something important) and you would like to print the size of the blob file to screen. This can be done quite easily by doing a query making use of the MySQL function OCTET_LENGTH()

For example:

SELECT OCTET_LENGTH(blob) FROM table

Blob being the column and table being the table in the database. The number returned is the size of the blob in bytes

There you go, quite easy to do but hard to find!

del.icio.us Digg Technorati StumbleUpon

Posted in General Opensource

2 Comments

  1. Michael John Grove

    I take it you needed to find out your blob file size? Just curious, why? is it a file for download?

    Thanks for taking the trouble. It’s always good, because one day I will need this - and THEN it will be avaliable through a Google search.

  2. jason

    Hi Micheal, yes thats pretty much the use of it. My actual use for it was a little more complex, but the is the idea. This article was kind of a book mark for me, you’d be surprised how hard it was to find hehehe :)

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.