![](/img/trans.png)
[英]H2 org.h2.jdbc.JdbcSQLSyntaxErrorException when inserting a Timestamp
[英]JdbcSQLSyntaxErrorException with h2 and jooq
我有一個列類型為 text[] 的表。
我將 dsl 與 jooq 與 H2 一起使用。該表的字符串值數組為:
+-------------+
|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 class。 當我執行以下查詢並打印結果時:
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 一起工作?
請查看DSL.arrayAggDistinct()
的@Support
注釋。 從 jOOQ 3.13 開始,它包括以下方言:
AURORA_POSTGRES
COCKROACHDB
HSQLDB
POSTGRES
在不久的將來,H2 將支持更多符合標准的ARRAY
類型,這與 PostgreSQL 的類似: https://github.com/h2database/h2database/issues/2190
屆時,jOOQ 還將增加對 H2 arrays 和數組函數的支持: https://github.com/jOOQ/jOOQ/issues/10175 ,但現在,您根本無法在 H2 上使用此功能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.