Skip to content

Run set-returning functions in the target list - #228

Merged
tamnd merged 1 commit into
mainfrom
projectset
Oct 9, 2026
Merged

tamnd merged 1 commit into
mainfrom
projectset

Conversation

@tamnd

@tamnd tamnd commented Oct 9, 2026

Copy link
Copy Markdown
Owner

Part of #3.

This change lets a query call a set-returning function in its target list, as the ProjectSet node of PostgreSQL does. The view pg_stats_ext_exprs and the body of _pg_expandarray in information_schema need this, and client tools often send such queries.

What changes

  • The analyzer marks each call of a function that returns a set. check_srf_placement gives the error of PostgreSQL for a call in WHERE, HAVING, FILTER, LIMIT, OFFSET, VALUES, a JOIN condition, a default, a check, an index and the parameters of EXECUTE.
  • A call inside CASE or COALESCE, and a call inside the arguments of an aggregate, gives the error of PostgreSQL with its hint and position.
  • The executor puts the calls in levels, as split_pathtarget_at_srfs does. A call is one level above the highest call in its arguments.
  • The calls of one level run side by side. A call with fewer rows gives nulls. When all calls of a level give no rows, the input row gives no rows.
  • The calls run after the aggregates and HAVING, and before ORDER BY, DISTINCT and LIMIT.
  • A function with more than one OUT parameter gives a row value.
  • The planner does not pull up a subquery with such a call, and it does not change EXISTS of such a subquery, as PostgreSQL does.
  • The view pg_stats_ext_exprs is now in the catalog with the OID of PostgreSQL 19, so all the views of system_views.sql are there. It needs row_security_active and pg_get_statisticsobjdef_expressions, which this change adds with pg_get_statisticsobjdef and pg_get_statisticsobjdef_columns. rupg has no objects of extended statistics, so these give null.
  • pg_get_viewdef does not put parentheses around a field before a subscript, as ruleutils.c does.
  • A call in GROUP BY and a call that gives a record with a polymorphic OUT type give the error 0A000 for now.

Test

  • The new session test target_srf runs a script and compares the result with the output of PostgreSQL 19 for the same script in a new database. It covers single calls, calls side by side, nested calls, calls inside expressions, strict calls with a null argument, aggregates, HAVING, ORDER BY, DISTINCT ON, LIMIT, subqueries, EXISTS, IN, row values and each error of a call in a wrong place.
  • The session test system_views now covers pg_stats_ext_exprs with its definition, and row_security_active and the functions of extended statistics with each error. The expected output is from PostgreSQL 19.
  • srvtest passed on server1: fmt, layers, style, clippy, all the workspace tests, the generated file checks and the docs.

@tamnd tamnd added this to the M2: Connect and introspect milestone Oct 9, 2026
@tamnd tamnd added kind/feature It does not do something that it must do. kind/compat A difference from PostgreSQL 19 at one of the five levels L1 to L5. area/sql The grammar, the lexer, the analyzer and the rewriter. labels Oct 9, 2026
@tamnd tamnd self-assigned this Oct 9, 2026
@tamnd
tamnd merged commit 4b6f327 into main Oct 9, 2026
5 checks passed
@tamnd
tamnd deleted the projectset branch October 9, 2026 19:30
This was referenced Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sql The grammar, the lexer, the analyzer and the rewriter. kind/compat A difference from PostgreSQL 19 at one of the five levels L1 to L5. kind/feature It does not do something that it must do.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant