2

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • You can do what Mikko suggested below, but imho, I think store the blob size in separate field is a better idea. – Thang Pham Mar 17 '12 at 23:49

2 Answers2

1

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.

Mikko Maunu
  • 41,366
  • 10
  • 132
  • 135
0

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
James
  • 17,965
  • 11
  • 91
  • 146