我有一个表,其列类型为文本[]。
我在带有H2的jooq中使用dsl。表的字符串值为数组:
+-------------+
|column_name |
+-------------+
|[str1, str2] |
|[str1, str2] |
|[str1, str2] |
|[str1, str2] |
|[str1, str2] |
|[str1, str2] |
|[str1, str2] |
|[str1, str2] |
|[str1, str2] |
|[str1, str2] |
|[str1, str2] |
|[str1, str2] |
|[str1, str2] |
|[str1, str2] |
|[str1, str2] |
|[str1, str2] |
|[str1, str2] |
|[str1, str2] |
|[str1, str2] |
+-------------+
表是使用jooq生成的Java类。当我执行以下查询并打印结果时:
println(
dsl
.select(Table.column_name)
.from(Table)
.fetch())
它打印出上面的表格数据。
但是当我执行时:
println(
dsl
.select(arrayAggDistinct(elementAt(Table.column_name, 1)))
.from(Table)
.fetch())
引发了异常:
o] Cause: org.h2.jdbc.JdbcSQLSyntaxErrorException: Column "db.Table.column_name" not found; SQL statement:
[info] select array_agg(distinct "db"."Table"."column_table"[1]) from db.Table [42122-200]
[info] at org.h2.message.DbException.getJdbcSQLException(DbException.java:453)
[info] at org.h2.message.DbException.getJdbcSQLException(DbException.java:429)
[info] at org.h2.message.DbException.get(DbException.java:205)
[info] at org.h2.message.DbException.get(DbException.java:181)
[info] at org.h2.expression.ExpressionColumn.getColumnException(ExpressionColumn.java:163)
[info] at org.h2.expression.ExpressionColumn.optimize(ExpressionColumn.java:145)
[info] at org.h2.expression.function.Function.optimize(Function.java:2594)
[info] at org.h2.expression.aggregate.AbstractAggregate.optimize(AbstractAggregate.java:92)
[info] at org.h2.expression.aggregate.Aggregate.optimize(Aggregate.java:705)
[info] at org.h2.command.dml.Select.prepare(Select.java:1206)
并且它在正常的PostgreSQL上可以执行,但是在使用H2的查询中给我错误。
我如何使其与H2一起使用?
请检查@Support
的DSL.arrayAggDistinct()
注释。从jOOQ 3.13开始,它包含以下方言:
DSL.arrayAggDistinct()
AURORA_POSTGRES
COCKROACHDB
HSQLDB
在不久的将来,H2将支持更多符合标准的POSTGRES
类型,这些类型更类似于PostgreSQL的ARRAY
类型>
那时,jOOQ还将增加对H2数组和数组函数的更多支持:https://github.com/h2database/h2database/issues/2190,但现在,您根本无法在H2上使用此功能。