[ 
https://issues.apache.org/jira/browse/CALCITE-5633?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17710258#comment-17710258
 ] 

Julian Hyde commented on CALCITE-5633:
--------------------------------------

Are table functions allows in the SELECT clause of an aggregate query (e.g. a 
query with a GROUP BY)?

In particular, if FIRST_N is a table function that accepts a number and a query 
as arguments, is the following valid? Note the use of 'dept.deptno' as a 
correlating variable.
{code:java}
SELECT deptno, FIRST_N(5, (SELECT ename FROM emp WHERE emp.deptno = 
dept.deptno)) AS emps
FROM dept
GROUP BY deptno{code}


> Allow table functions to be inside select list
> ----------------------------------------------
>
>                 Key: CALCITE-5633
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5633
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.34.0
>            Reporter: Dmitry Sysolyatin
>            Priority: Major
>
> Currently, it is impossible to use table functions inside select list.
> For example:
> {code}
> SELECT UNNEST(ARRAY[1,2,3]);
> {code}
> {code}
> SELECT table(generate_series(1,2)); // generate_series is user defined table 
> function
> {code}
> Engines like PostgreSQL support it[1]:
> {quote}Functions returning sets can also be called in the select list of a 
> query. For each row that the query generates by itself, the set-returning 
> function is invoked, and an output row is generated for each element of the 
> function's result set
> {quote}
> [1] https://www.postgresql.org/docs/current/xfunc-sql.html



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to