我有这样的功能:
CREATE OR REPLACE FUNCTION test() RETURNS
TABLE(my_date date, gates smallint, area_type character(1),
area_sizes float[], area_canvases float[]) AS $$
BEGIN
return query
select coalesce(s.my_date, r.my_date) as my_date, coalesce(s.gates, r.gates) as gates, coalesce(s.area_type, r.area_type) as area_type, s.area_sizes, r.area_canvases
from (select my_date, gates, area_type, area_sizes from table1 where area_type = 'X') s
full join (select my_date, gates, area_type, area_canvases from table2 where area_type = 'Y') r
on r.my_date = s.my_date;
END $$ language plpgsql;
当我运行它时select * from test();
,我得到的是:
ERROR: column reference "my_date" is ambiguous
LINE 4: my_date,
如果未包含在函数中的查询可以正常工作,但我无法使其在其中工作。任何想法?
计划者无法理解您在那里提到的 my_date 。参数中的一个或 table1(或 table2)中的一个。正确的语法应该如下所示;