0

I'm using a Postgresql database. I connect to it using the Postgresql JPA driver, and use Spring-data CRUD repository to access it (with a custom query).

My Repository interface looks like this:

public interface MyRepository extends CrudRepository<MyEntity,MyEntity.Id> {

@Query(value = """
        SELECT vin as vin FROM unnest(array[:vins]) as params(vin)
        """, nativeQuery = true)
List<String> findUnknownVins(List<String> vins);


}

My custom query currently is not finished, but a minimal example which already fails. The query in the current state should just retrieve the vins that are provided as a parameter. Later on I want to use the query to retrieve unfound vins from the database.

But for now, this query already fails. When I execute it from a SQL Console, it works. But when I use it from my Repository, I get an exception:

org.postgresql.util.PSQLException: ERROR: a column definition list is required for functions returning "record"

The exception occurs at the unnest() function. To my understanding, with the "as params(vin)" I'm providing a column definition list, and Spring Data / JPA should be able to map the return value to a List.

  • 1
    [PostgreSQL: ERROR: 42601: a column definition list is required for functions returning "record"](https://stackoverflow.com/questions/8605174/postgresql-error-42601-a-column-definition-list-is-required-for-functions-ret) - add type, `as params(vin varchar)`. – Ponder Stibbons May 08 '23 at 14:52

0 Answers0