Repository navigation
Conversation
…unknown in the body
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #939.
The typecheck rules gave the parameters of a SQL function their declared types inside the body, including polymorphic ones. With
$1 anyelement, a call likearray_prepend($1, $2)was matched againstarray_prepend(anycompatible, anycompatiblearray)withanyelementas the actual argument type, which no candidate accepts:This is the false positive #939 found in
polymorphism.sql.Postgres never analyses such a body with the declared types. When
check_function_bodiesis on,fmgr_sql_validatoronly raw-parses the body of a function with polymorphic arguments. At call time,prepare_sql_fn_parse_infoswaps each polymorphic parameter type for the type of the call's argument before it parses the body (functions.c#L286). So the type of a polymorphic parameter in the body is whatever the caller passes, and we can't know it from the body.BEGIN ATOMICbodies, which are analysed at creation with the declared types, aren't affected: Postgres rejects polymorphic arguments there ("SQL function with unquoted function body cannot have polymorphic arguments").The fix:
function_param_typenow returns unknown for parameters of a pseudo-type. Polymorphic types are the only pseudo-types SQL functions accept as parameters (pg_proc.c#L873). Expressions that use these parameters are therefore unknown, and nothing is reported for them. Parameters of concrete types (including arrays) still have their declared types.Tests: a new
functionArgumentMismatch/function_parameters.sqlspec. It checks that a concrete parameter is still checked (length(n)withn intis reported) and thatarray_prepend($1, $2)andlength(a)with polymorphic parameters aren't. Thepolymorphismentry is gone from the harness'sKNOWN_FALSE_POSITIVES, which is now empty. The regression snapshots only lose their "Known false positives" section.Not covered: we don't infer the result types of polymorphic SQL functions at call sites from the body. That already went through the function's declared signature and is unchanged.