Hello Tom,
thanks for the quick response.
You are probably right with your assumption of a not convertible substring, but some questions remain:
1. When the question runs succesfully, all lines are subject to the join of qj (newcol_imp and oldcol_imp heve exact the same number of lines, matching logically), but why does a limitation of the result set trigger the error?
(There really may be some substrings from declarations of numeric(4,1) which are not excluded properly from conversion to smallint.
The '0'||<rest> tries to handle an empty string)
2. Why is it reporting an syntax error (supposed at parse time) and not a runtime error (supposed at execution time)
3. Why does an uncorrelated qual like and onum < 100 trigger an error too?
( I know that a limitation can change the choosen plan, but which one cannot be seen because of the error.)
The behavior of having a succesfull full query, but getting the error with some quals seems to me very unintuitive.
PS: The exactness and correctness of this specific query is certainly not overall important for me, but I wanted to point out this very unexpected behavior for some other users.
When I find some time, I'll try to provide some anonymized data.
Best regards