gpt4 book ai didi

postgresql - jOOQ:只获得一个结果而不是所有现有条目

转载 作者:行者123 更新时间:2023-11-29 13:54:43 24 4
gpt4 key购买 nike

我正在与 jOOQ 通话:

List<StoreRecord> fetchInto = this.ctx
.select(Store.STORE.NAME)
.from(Store.STORE)
.join(StoreAdminStore.STORE_ADMIN_STORE)
.on(StoreAdminStore.STORE_ADMIN_STORE.ID.eq(id))
.where(Store.STORE.ID.eq(StoreAdminStore.STORE_ADMIN_STORE.STORE_ID))
.fetchInto(StoreRecord.class);

for (StoreRecord store: fetchInto) {
LOGGER.debug(store.getName());
}

应该复制这个 PostreSQL 语句:

SELECT
store.name
FROM store
JOIN store_admin_store ON store_admin_store.store_admin_id = 1
WHERE store.id = store_admin_store.store_id

但是,jOOQ 向我提供了一个只有 一个 StoreRecord 的列表,即使这里有五个符合特定条件的条目..

我做错了什么?

最佳答案

你的 jOOQ 查询和你的 SQL 查询不一样。

jOOQ 查询:

-- Is
STORE_ADMIN_STORE.ID.eq(id)

-- Should be
STORE_ADMIN_STORE.STORE_ADMIN_ID.eq(id)

SQL查询:

store_admin_store.store_admin_id = 1

就目前而言,您的查询仅从关系表 (ID = 1) 返回一行,然后仅将单个相关商店连接到它。

除此之外,您可能应该在 ON 子句和 WHERE 子句之间切换谓词。现在,您将连接谓词放在 WHERE 子句中,而过滤谓词放在 ON 子句中...

关于postgresql - jOOQ:只获得一个结果而不是所有现有条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34437988/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com