Open DrewKimball opened 9 months ago
Snippet from postgres docs:
If the expression's result data type doesn't match the variable's data type, the value will be coerced as though by an assignment cast (see [Section 10.4](https://www.postgresql.org/docs/current/typeconv-query.html)). If no assignment cast is known for the pair of data types involved, the PL/pgSQL interpreter will attempt to convert the result value textually, that is by applying the result type's output function followed by the variable type's input function. Note that this could result in run-time errors generated by the input function, if the string form of the result value is not acceptable to the input function.
Relevant comment in postgres source: https://github.com/postgres/postgres/blob/e722846daf4a37797ee39bc8ca3e78a4ef437f51/src/pl/plpgsql/src/pl_exec.c#L7856-L7870
This issue tracks a difference between postgres and CRDB when coercing a PLpgSQL expression into a type that is too narrow. For context: Explicit casts succeed, and truncate the value:
Assignment casts fail with an error:
Finally, PLpgSQL type coercion succeeds, but does not truncate:
CRDB matches behavior for the first two cases, but truncates the value for the last case:
Jira issue: CRDB-34004