commit 678834d2fc1d74710ca36b075be0989832e15cec Author: David G. Johnston Date: Fri Oct 2 20:02:00 2020 +0000 Minor cleanup and rewording of plpgsql docs diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml index 815912666d..4af66a637c 100644 --- a/doc/src/sgml/plpgsql.sgml +++ b/doc/src/sgml/plpgsql.sgml @@ -856,7 +856,7 @@ SELECT expression to the main SQL engine. While forming the SELECT command, any occurrences of PL/pgSQL variable names - are replaced by parameters, as discussed in detail in + are replaced by query parameters, as discussed in detail in . This allows the query plan for the SELECT to be prepared just once and then reused for subsequent @@ -945,11 +945,13 @@ my_record.user_id := 20; - Any PL/pgSQL variable name appearing - in the command text is treated as a parameter, and then the + Any PL/pgSQL variables appearing + in the command text are replaced by query parameters, and then the current value of the variable is provided as the parameter value at run time. This is exactly like the processing described earlier for expressions; for details see . + If the SQL command being executed is incapable of returning a result + it does not accept query parameters. @@ -2507,7 +2509,7 @@ $$ LANGUAGE plpgsql; - PL/pgSQL variables are substituted into the query text, + PL/pgSQL variables are converted into query parameters, and the query plan is cached for possible re-use, as discussed in detail in and . @@ -4583,9 +4585,9 @@ CREATE EVENT TRIGGER snitch ON ddl_command_start EXECUTE FUNCTION snitch(); SQL statements and expressions within a PL/pgSQL function can refer to variables and parameters of the function. Behind the scenes, PL/pgSQL substitutes query parameters for such references. - Parameters will only be substituted in places where a parameter or - column reference is syntactically allowed. As an extreme case, consider - this example of poor programming style: + Query parameters will only be substituted in places where syntactically allowed + (in particular, identifiers can never be replaced with a query parameter.) + As an extreme case, consider this example of poor programming style: INSERT INTO foo (foo) VALUES (foo); @@ -4597,13 +4599,6 @@ INSERT INTO foo (foo) VALUES (foo); variable. - - - PostgreSQL versions before 9.0 would try - to substitute the variable in all three cases, leading to syntax errors. - - - Since the names of variables are syntactically no different from the names of table columns, there can be ambiguity in statements that also refer to @@ -5253,13 +5248,14 @@ HINT: Make sure the query returns the exact list of columns. - If a name used in a SQL command could be either a column name of a - table or a reference to a variable of the function, - PL/SQL treats it as a column name. This corresponds - to PL/pgSQL's + If a name used in a SQL command matches a known column name and also + a named variable within the function, + PL/SQL treats it as a column name. + By default, PL/pgSQL will treat it as a variable, + but one can specify plpgsql.variable_conflict = use_column - behavior, which is not the default, - as explained in . + (see for specifics) + to change the behavior to match PL/SQL. It's often best to avoid such ambiguities in the first place, but if you have to port a large amount of code that depends on this behavior, setting variable_conflict may be the