Hi Lukas,
The schema for the table is not relevant in this case because it doesn't
contain the array field, the array field is constructed via *array_agg*
aggregation function. Simple example:
select array_agg(some_field) as theArray
from sometable
group by some_field
CREATE TABLE sometable (
some_field varchar(30)
);
On Wednesday, September 6, 2017 at 2:00:12 AM UTC-4, Lukas Eder wrote:
>
> Hi Max,
>
> In principle, that sort of thing should work, but perhaps the PostgreSQL
> JDBC driver isn't really delivering an array but a wrapper for an array for
> your query? What's the DDL of sometable?
>
> Cheers,
> Lukas
>
> 2017-09-06 0:12 GMT+02:00 Max Kremer <[email protected] <javascript:>>:
>
>> Hi,
>>
>> I have a SQL result set that includes a varchar array as one of the
>> columns. I'm mapping over the Result<Record> returned by fetch() and
>> manually populating a pojo but I'm having trouble populating the String[]
>> array field of the pojo.
>>
>>
>>
>> d.fetch("select array_agg(some_field) as theArray from sometable group
>> by some_field")
>> .stream()
>> .map(r -> {
>> SalesTouchPoint stp = new SalesTouchPoint();
>> stp.setAudience(r.getValue("people", Integer.class));
>> stp.setEpc(r.getValue("epc", Double.class));
>> stp.setTouchPoints(r.getValue("theArray", String[].
>> class));
>> return stp;
>> })
>> .collect(Collectors.toList());
>>
>>
>>
>>
>> As you can see from the above code I'm using Record.getValue (or
>> Record.get) to access the column "theArray" from the result set. I'm
>> getting a class cast exception:
>>
>> Caused by: org.jooq.exception.DataTypeException: Cannot convert from [
>> Ljava.lang.String;@5a6782c3 (class java.lang.String) to class [Ljava.lang
>> .String;
>> at org.jooq.tools.Convert$ConvertAll.fail(Convert.java:1118) ~[na:na]
>> at org.jooq.tools.Convert$ConvertAll.from(Convert.java:1007) ~[na:na]
>> at org.jooq.tools.Convert.convert0(Convert.java:316) ~[na:na]
>> at org.jooq.tools.Convert.convert(Convert.java:308) ~[na:na]
>> at org.jooq.tools.Convert.convert(Convert.java:380) ~[na:na]
>> at org.jooq.impl.AbstractRecord.get(AbstractRecord.java:260) ~[na:na]
>> at org.jooq.impl.AbstractRecord.getValue(AbstractRecord.java:1222) ~[na:
>> na]
>>
>>
>> Everything I've read in the docs suggests that JOOQ handles SQL array
>> types just fine. What am I doing wrong?
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "jOOQ User Group" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
You received this message because you are subscribed to the Google Groups "jOOQ
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.