postgresql - 在真子句上左侧连接 Postgresql 没有得到它
问题描述
努力理解左加入横向。
begin;
create temp table manufacturers(id serial primary key, name text);
create temp table get_product_names (pid integer, id integer, product text,
CONSTRAINT fk_id FOREIGN KEY(id) REFERENCES manufacturers(id) );
insert into manufacturers(name) values('m1'),('m2'),('m3'),('m4'),('m5');
insert into get_product_names(pid,id, product) values(1,1,'typea');
insert into get_product_names(pid,id, product) values(2,2,'typeb');
insert into get_product_names(pid,id, product) values(3,4,'typec');
commit;
从手册中引用
LEFT JOIN 到 LATERAL 子查询通常特别方便,因此即使 LATERAL 子查询没有为它们生成任何行,源行也会出现在结果中。例如,如果 get_product_names() 返回制造商生产的产品名称,但我们表中的一些制造商当前没有生产产品,我们可以找出哪些是这样的:
SELECT m.name
FROM manufacturers m LEFT JOIN LATERAL get_product_names(m.id) pname ON true
WHERE pname IS NULL;
但是当我执行代码时:发生以下错误。
No function matches the given name and argument types. You might need to add explicit type casts.
那么如何在真子句上复制左侧连接。或者我的代码哪里出错了?
解决方案
你没有创建一个名为 get_product_names(int) 的函数。
您不能横向连接到裸表名称。它必须是子查询,是函数。
推荐阅读
- javascript - Javascript数组过滤两个搜索框
- java - 怎么修 '
HackerRank 中的预期错误 - ruby-on-rails - Searchkick 突出显示不必要的单词
- python - 如何在巨大的数据帧上实现并行处理
- asp.net-core - ASP.Net Core 2.2 wwwroot 静态内容托管在 S3 和 CloudFront 上
- flutter - 如何从滚动子项的小部件中删除滚动条
- node.js - Express 找不到 Webpack 包
- performance - CPU或GPU上的乘法累加运算,仅加法,仅乘法和二进制运算之间的性能比是多少?
- angular - 如何使用快递通过有角度的服务器发送数据?404错误
- sql - 创建分层视图树类型