0

我正在尝试构建一个满足以下条件的简单函数(需要使用 Hasura API fwiw链接

Function behaviour: ONLY STABLE or IMMUTABLE
Return type: MUST be SETOF <table-name>
Argument modes: ONLY IN

这是功能

CREATE FUNCTION fn_sum_views(text) RETURNS SETOF page_analytics AS $$
  SELECT prodID, sum(views) FROM page_analytics WHERE prodID = $1 group by prodID
$$ LANGUAGE SQL STABLE;

我得到错误:"column \"prodid\" does not exist"。当我使用page_analytics.prodID, "page_analytics.prodID", 或\"page_analytics.prodID\"

4

1 回答 1

2

对于任何包含大写字母的表名或列名,请始终确保使用双引号。否则,它们将转换为小写

CREATE FUNCTION fn_sum_views(text) RETURNS SETOF page_analytics AS $$
  SELECT "prodID", sum(views) FROM page_analytics WHERE "prodID" = $1 group by "prodID"
$$ LANGUAGE SQL STABLE;

另请注意,在引用 "page_analytics"."prodID" 时也可以使用。

于 2019-07-03T02:08:50.197 回答