Repository navigation
fix(typecheck): don't substitute output columns or qualified columns as parameters - #838
Merged
Merged
Conversation
…stgres accepts RETURNS TABLE and OUT parameters were collected as parameters of SQL function bodies, and a parameter name matched at any position of a qualified reference, so `r.received_at` was replaced by a literal when an output column was named `received_at`. Fixes #835
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.
The database type check no longer replaces
RETURNS TABLE/OUTcolumns, or qualified column references liker.received_at, with parameter literals inLANGUAGE sqlbodies. The issue's function no longer reportsnon-integer constant in ORDER BY.Only input parameters are in scope
get_sql_fn_signaturecollected every parameter,OUTandTABLEincluded. Postgres only exposes input parameters (IN,INOUT,VARIADIC) to the body, by name and as$n(get_func_input_arg_names, called fromprepare_sql_fn_parse_info). Output columns are now skipped. That also fixes$nnumbering when anOUTparameter comes before an input, and the static resolver:SELECT xwithOUT x intis now reported as an unknown column, as Postgres does. Before,xcounted as a parameter and nothing was reported.Qualified names follow Postgres' rules
find_matching_identifierused to match a parameter name at any position in a dotted path, sor.received_atmatched a parameter namedreceived_at. It now accepts only the forms insql_fn_post_column_ref:param,fn_name.param,param.fieldandfn_name.param.field, withfn_name.paramtaking precedence. Any other qualifier is a column reference and is left alone. Qualified references are not excluded outright, becausefn_name.paramand composite fields (#705) are valid parameter references.Not in this PR
Postgres never lets a parameter override a table column (
if (var != NULL) return NULL). The EXPLAIN check doesn't know which columns are in scope, so an unqualified reference that names both an input parameter and a column, e.g.f(id bigint) … ORDER BY id, is still replaced by a literal. The same applies toparam.fieldwhenparamis also a FROM alias. Fixing this needs scope information from the resolver, so it is left for a follow-up.Fixes #835