I want to show a list of file names read from a database and their sizes, but if I read the value of the blob the query is very slow. How I can calculate the size of the blob without reading it?
I'm using EclipseLink.
I want to show a list of file names read from a database and their sizes, but if I read the value of the blob the query is very slow. How I can calculate the size of the blob without reading it?
I'm using EclipseLink.
There is no such a facility in JPQL. Also how it is done with native query probably depends about the database. At least with MySQL and Oracle following works:
SELECT LENGTH(blob_field) FROM table_name;
If you use JPQL, LENGTH
function is limited to character types, so it is not applicable for BLOB
. Of course there can be persistence provider extension which makes it work.
JPQL supports LENGTH, so this should also work in JPQL,
Select LENGTH(o.blobField) from MyObject o
Otherwise you could always use FUNC in JPQL,
Select FUNC('LENGTH', o.blobField) from MyObject o