On Mon, Nov 9, 2020 at 6:50 AM 德哥 <digoal@126.com> wrote:
but the execution behavior is biased, either do not replace the value of the variable during the execution, but directly use the table name corresponding to the variable name.
I've lost something in translation. There is no bias (not sure what that means in this context) or variability/ambiguity here. The thing in front of %RowType is always an identifier - specifically, a table. That your function also has a variable of the same name is immaterial to PostgreSQL since none of the variables in the function are ever considered when it is expecting/required-to-have an identifier to fulfill the syntax. This is well-defined in PostgreSQL pl/pgsql and so the observed behavior is not buggy.
"select tbl%rowtype into a%rowtype" is effectively (cast tbl%rowtype as a%rowtype) which is a well-defined and the user is responsible for ensuring the two rowtypes are compatible. "tbl" and "a" are compatible, "b" and "a" are not, which your original post demonstrates.