0

I had a repository like so:

@Repository
interface Repository {
    @Query("insert into t values (cube(:array))")
    void save(float[] array)
}

which gives there error Unable to find server array type for provided name REAL.

I even tried to manually build a query string of the form: insert into t values (cube(array[0.1,0.3,0.2,...]::float4[])) and also insert into t values (cube('{0.1,0.3,0.2,...}'::float4[])) but I get the same error.

I added the float4[] cast as in this question the user seems to solve the error by using a float4 array instead of real array.

I also tried to use the Connection.createArrayOf("float4", ...) but when I try to auto-wire the Connection I get this error on startup:

required a bean of type 'java.sql.Connection' that could not be found.

Tobi Akinyemi
  • 804
  • 1
  • 8
  • 24
  • Could you clarify what you are trying to achieve? All examples of `CUBE` with Postgres use it in a `GROUP BY` clause where it takes a list of column names as arguments. I'm not sure what the purpose would be in an insert statements with an array of numbers as an argument. – Jens Schauder May 04 '21 at 07:49
  • @JensSchauder I'm storing a vector in my table. – Tobi Akinyemi May 05 '21 at 18:41
  • @JensSchauder The problem is the library is mapping `float[]` to `real[]`, which is broken.I had to manually map my `float[]` to a `java.sql.Array` with `type="float4"` – Tobi Akinyemi May 05 '21 at 18:44
  • which involved the use of a `JdbcTemplate` – Tobi Akinyemi May 05 '21 at 21:40

0 Answers0