使用另一个查询的结果更新 postgres 字段

发布于 2025-01-11 04:29:18 字数 1357 浏览 4 评论 0原文

我有以下格式的表格。

Moderations table
+---------+------------+--------------+
| mod_id  | post_id    | is_moderated |
+---------+------------+--------------+
|  1      |    1       |    true      |
+---------+------------+--------------+
|  2      |    2       |    false     |
+---------+------------+--------------+
|  1      |    3       |    false     |
+---------+------------+--------------+
|  3      |    4       |    false     |
+---------+------------+--------------+
|  4      |    5       |    false     |
+---------+------------+--------------+

我有另一个表来跟踪特定模块是否处于活动状态。

Moderator Table
+---------+---------------+
| mod_id  | is_mod_active |
+---------+---------------+
|  1      |     true      |
+---------+---------------+
|  2      |     false     |
+---------+---------------+
|  3      |     false     |
+---------+---------------+
|  4      |     true      |
+---------+---------------+

我执行以下查询来获取未经审核的审核请求,以及分配的审核者已变为非活动状态的审核请求。

SELECT * 
from 
    moderation 
left join moderator 
    on mod_id=user_id 
where 
    is_mod_active = false and 
    is_moderated = false
order by 
created_on

对于这些选定的行,我想使用以下查询更新 mod_id 字段

SELECT mod_id 
FROM 
    moderator
WHERE
    is_mod_active = true

第二个查询将比第一个查询更短或更长。有办法更新这个吗?

I have table with following format.

Moderations table
+---------+------------+--------------+
| mod_id  | post_id    | is_moderated |
+---------+------------+--------------+
|  1      |    1       |    true      |
+---------+------------+--------------+
|  2      |    2       |    false     |
+---------+------------+--------------+
|  1      |    3       |    false     |
+---------+------------+--------------+
|  3      |    4       |    false     |
+---------+------------+--------------+
|  4      |    5       |    false     |
+---------+------------+--------------+

I have another table that tracks whether a particular mod is active.

Moderator Table
+---------+---------------+
| mod_id  | is_mod_active |
+---------+---------------+
|  1      |     true      |
+---------+---------------+
|  2      |     false     |
+---------+---------------+
|  3      |     false     |
+---------+---------------+
|  4      |     true      |
+---------+---------------+

I perform following query to get the moderation requests that are unmoderated, and for whom assigned moderator has gone inactive.

SELECT * 
from 
    moderation 
left join moderator 
    on mod_id=user_id 
where 
    is_mod_active = false and 
    is_moderated = false
order by 
created_on

for these selected rows I would like to update the mod_id field with following query

SELECT mod_id 
FROM 
    moderator
WHERE
    is_mod_active = true

The second query will be shorter or longer than the first query. Is there a way to update this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文