I am working on porting a database with Firebird to PostgreSQL and encounter a lot of errors related to type incompatibility. For example, let's take one simple function, in fact, it can be of any complexity:
CREATE OR REPLACE FUNCTION f_Concat3 ( s1 varchar, s2 varchar, s3 varchar ) RETURNS varchar AS $body$ BEGIN return s1||s2||s3; END; $body$ LANGUAGE 'plpgsql' IMMUTABLE CALLED ON NULL INPUT SECURITY INVOKER LEAKPROOF COST 100; When calling this function in the context of a select from Firebird, you can pass various types of arguments to arguments, Firebird will automatically turn date / integer / float into strings and execute this function.
PostgreSQL has strict typing and when trying to call this function in the form: f_Concat3 ('1', 2, 345.345) error will pop up:
function f_Concat3 (unknown, integer, numeric) not found.
If the first argument of the type unknown postgres automatically leads to the desired string type, then with the second and third argument it can no longer cope.
The documentation recommends using an explicit cast, in this case f_Concat3 ('1'::varchar, 2::varchar, 345.345::varchar) will work successfully.
Alternatively, you can get clones of functions with all possible variations of the types of arguments, but this is clearly a bad approach and will not work for large functions, since inside you will have to again monitor type compatibility.
And the problem is that we use a single code base for all DBMSs and our own language to build the forms and requests of the application. Therefore, adding an explicit cast to all queries with function calls will break compatibility with other DBMSs.
I’m confused that the numeric or double precision argument cannot be fed to an integer , and the handler cannot turn the date / number into a string automatically. It seems there were even problems converting integer to smallint and vice versa. Most DBMSs are fine with this.
Is it possible to get around this problem without explicit type conversion?
anytypes of postgresql.org/docs/8.4/static/datatype-pseudo.html - Mikereturn s1::varchar||s2:varchar...- Mike