获取“范围内”的两行对于 PostgreSQL 函数调用:交叉连接?
我有一个用户定义的函数 similarity()
来比较两个用户并返回一个分数。现在,调用查询看起来像:
SELECT similarity(user1, user2)
FROM (
SELECT users.id
FROM users AS user1
WHERE users.id = 123
)
CROSS JOIN
(
SELECT users.id
FROM users AS user2
WHERE users.id = 456
);
这感觉很混乱。有没有更好的方法来设置函数调用的两个用户?
I have a user-defined function similarity()
that compares two users and returns a score. Right now, the calling query looks like:
SELECT similarity(user1, user2)
FROM (
SELECT users.id
FROM users AS user1
WHERE users.id = 123
)
CROSS JOIN
(
SELECT users.id
FROM users AS user2
WHERE users.id = 456
);
This feels messy. Is there a better way to set up the two users for the function call?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果每个表中只有一个(似乎
id
是一个 PK),那么If there is only one from each table (seems likely that
id
is a PK) then完全相同的简化形式:
Simplified form that does exactly the same: