Your function has a couple of smallint
parameters.
But in the call, you are using numeric literals that are presumed to be type integer
.
A string literal or string constant ('123'
) is not typed immediately. It remains type “unknown” until assigned or cast explicitly.
However, a numeric literal or numeric constant is typed immediately. The manual:
A numeric constant that contains neither a decimal point nor an
exponent is initially presumed to be typeinteger
if its value
fits in typeinteger
(32 bits); otherwise it is presumed to be type
bigint
if its value fits in typebigint
(64 bits); otherwise it is
taken to be typenumeric
. Constants that contain decimal points and/or
exponents are always initially presumed to be typenumeric
.
Also see:
Solution
Add explicit casts for the smallint
parameters or pass quoted (untyped) literals.
Demo
CREATE OR REPLACE FUNCTION f_typetest(smallint)
RETURNS bool AS 'SELECT TRUE' LANGUAGE sql;
Incorrect call:
SELECT * FROM f_typetest(1);
Correct calls:
SELECT * FROM f_typetest('1');
SELECT * FROM f_typetest(smallint '1');
SELECT * FROM f_typetest(1::int2);
SELECT * FROM f_typetest('1'::int2);
db<>fiddle here
Old sqlfiddle.