---
title: "Comment by Poushali Sil on \"Hibernate 6: custom SQL functions in Spring Data JPA repositories\" | Hashnode"
description: "Very Useful article. I want to know one thing. If the return type of the custom sql function in Array, then How should one handle return type of the function"
url: "https://hashnode.com/posts/hibernate-6-custom-functions/6528e89bfade2f3801c64e31/comment/654d202e648458030f2f3bc8"
---

[Discussion](https://hashnode.com/posts/hibernate-6-custom-functions/6528e89bfade2f3801c64e31)

Comment [Hibernate 6: custom SQL functions in Spring Data JPA repositories](https://hashnode.com/posts/hibernate-6-custom-functions/6528e89bfade2f3801c64e31)

[Poushali Sil](https://hashnode.com/@Silp)

[Nov 9, 2023](https://hashnode.com/posts/hibernate-6-custom-functions/6528e89bfade2f3801c64e31/comment/654d202e648458030f2f3bc8)

Very Useful article. I want to know one thing. If the return type of the custom sql function in Array, then How should one handle return type of the function

[Arnau Aregall](https://hashnode.com/@ArnauAregall)

[Nov 10, 2023](https://hashnode.com/posts/hibernate-6-custom-functions/6528e89bfade2f3801c64e31/comment/654d202e648458030f2f3bc8#reply-654de64f5bb6e20fe50a3150)

Thanks for your comment!

If I got it correctly, you would like to handle that your custom SQL functions returns an array.

Then you could register your function with your aimed return type with a `BasicTypeReference` instance.

```
private static final BasicTypeReference<String[]> RETURN_TYPE = new BasicTypeReference<>("string[]", String[].class, SqlTypes.ARRAY);
```

As an example, a function called `array_first_and_last` that gets the first and last elements of the array would be somehow like this in the post example:

```
select array[p.tags[1], p.tags[array_length(p.tags, 1)]] 
from products p
 where ...
```

After a correct registering and rendering implementation, you should be able to use it in a JPA repository as follows:

```
@Query("select array_first_and_last(p.tags) as array from Product p where p.sku = :sku")
String[] getFirstAndLastTagsBySku(@\Param("sku") String sku);
```

Hope it helps! Cheers 👍
