user2113422
user2113422

Reputation:

MySQL get blob N bytes

I'd like to know if you can query a blob (large/medium any kind) column and retrieve the bytes from N to M so you can query a huge blob file and only get small chunks of it in your resultset. If this is possible in MySQL, how can you do it (an example please!)?

I found this question for plain text but what about doing the same for bytes?

Upvotes: 2

Views: 3952

Answers (1)

stefan
stefan

Reputation: 5068

You can find the answer right here: MySQL blob: how to get just a subset of the stored data

MySQL treats blobs the same as strings (more or less):

BLOB values are treated as binary strings (byte strings). They have no character set, and sorting and comparison are based on the numeric values of the bytes in column values.

So all the usual string functions work on blobs. In particular, you can use substring to grab just part of of a blob.

That said, storing a multi-gigabyte data file in a relational database as a BLOB isn't the best thing to do. You'd be better off storing the file's metadata in the database and leaving the file itself in the file system; file systems are pretty good at managing files, relational databases are good at handling structured data.

Upvotes: 4

Related Questions