我有以下选择查询创建:
final DSLContext create = DSL.using(..., SQLDialect.POSTGRES);
create
.select(DSL.field("identifier"), DSL.field("name"),
create.selectCount()
.from(DSL.table("person"))
.where(DSL.field("identifier").eq(DSL.field("personOuter.identifier")))
.asField("count"))
.from(DSL.table("person").as("personOuter"))
Run Code Online (Sandbox Code Playgroud)
jOOQ生成以下查询:
select
identifier,
name,
(select count(*)
from person
where identifier = personOuter.identifier) as "count"
from person as "personOuter"
Run Code Online (Sandbox Code Playgroud)
查询应该是:
select
identifier,
name,
(select count(*)
from person
where identifier = personOuter.identifier) as "count"
from person as personOuter
Run Code Online (Sandbox Code Playgroud)
后一种查询在PostgreSQL中完美运行.表别名不应该用引号括起来.
这是一个错误吗?
(请注意,查询非常愚蠢.我正在玩jOOQ进行评估.)
以下"黑客"有效:
create
.select(DSL.field("identifier"), DSL.field("name"),
create.selectCount()
.from(DSL.table("person"))
.where(DSL.field("identifier").eq(DSL.field("personOuter.identifier")))
.asField("count"))
.from("person as personOuter")
Run Code Online (Sandbox Code Playgroud) 我有一份条件清单:
List<Condition> conditions = ...;
Run Code Online (Sandbox Code Playgroud)
将这些条件组合(或组合)成新条件的最简单方法是什么?
Condition condition = and(conditions);
Run Code Online (Sandbox Code Playgroud)
JOOQ是否具有实用功能?我同意这很容易写,但我宁愿不重新发明轮子.
jOOQ是否支持PostgreSQL数组函数和运算符?
array(select ... from ...)
array_length(array)
...
Run Code Online (Sandbox Code Playgroud)
有关概述,请参见http://www.postgresql.org/docs/current/static/functions-array.html.
编辑
我在下面添加了一个示例查询.我还添加了查询来创建和填写表格,因此请尝试查询.
drop table if exists person_country;
drop table if exists person;
drop table if exists country;
create table person
(
identifier integer not null,
name text not null,
primary key(identifier)
);
create table country
(
identifier integer not null,
name text not null,
primary key(identifier)
);
create table person_country
(
person_identifier integer not null,
country_identifier integer not null,
primary key(person_identifier, country_identifier),
foreign key(person_identifier) references person,
foreign key(country_identifier) references country …Run Code Online (Sandbox Code Playgroud)