简体   繁体   English

jooq从表的特定分区中选择

[英]jooq select from a particular partition of the table

What is the right way to execute a select query on a particular partition of a table. 在表的特定分区上执行选择查询的正确方法是什么。 For exmample I have a employees table that is range partitioned on a particular column. 例如,我有一个employees表,该表在一个特定的列上进行了分区。

Currently I do: 目前,我正在:

Result<Record> fetch = DSL.using(configuration())
  .select()
  .from(EMPLOYEES)
  .fetch();

what is the right way to execute the below sql (where p2 is a partition) 什么是执行以下sql的正确方法(其中p2是分区)

SELECT * FROM employees PARTITION (p2);

UPDATE 1 What about for update/insert when I am using Updatable record, example: UPDATE 1我使用可更新记录时如何进行更新/插入,例如:

employeeRecord.attach(configuration())
employeeRecord.update(); // or insert

I assume I can do something like this but would that then handle optimistic lock case (which I am using via the version column on my table) 我假设我可以做这样的事情,但是可以处理乐观的锁情况(我通过表的version列使用)

DSL.using(configuration())
                    .update("{0} partition (p2)", EMPLOYEES)
                    .set(EMPLOYEES.NAME, "abc")
                    .where(EMPLOYEES.ID.eq(123))
                    .execute();

jOOQ currently doesn't support PARTITION clauses on tables. jOOQ当前不支持表上的PARTITION子句。 The relevant feature request is: https://github.com/jOOQ/jOOQ/issues/2774 相关功能请求为: https : //github.com/jOOQ/jOOQ/issues/2774

You can easily work around this limitation by using the plain SQL templating API: https://www.jooq.org/doc/latest/manual/sql-building/plain-sql-templating 您可以使用简单的SQL模板API轻松解决此限制: https : //www.jooq.org/doc/latest/manual/sql-building/plain-sql-templating

Result<Record> fetch = DSL.using(configuration())
  .select()
  .from("{0} partition (p2)", EMPLOYEES)
  .fetch();

The above is convenience for: 上面是为了方便:

Result<Record> fetch = DSL.using(configuration())
  .select()
  .from(DSL.table("{0} partition (p2)", EMPLOYEES))
  .fetch();

Did you try going with examples from here, like 您是否尝试过此处的示例,例如

create.select(t.BOOKED_AT, t.AMOUNT,
         sum(t.AMOUNT).over().partitionByOne()
                      .orderBy(t.BOOKED_AT)

https://www.jooq.org/doc/3.0/manual/sql-building/column-expressions/window-functions/ https://www.jooq.org/doc/3.0/manual/sql-building/column-expressions/window-functions/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM