Pass a database query parameter as a function casted parameter

So I know you can pass query parameters as function parameter:

This:

CREATE FUNCTION add_one (integer) RETURNS INTEGER AS '
    BEGIN
        RETURN $1 + 1;
    END;
' LANGUAGE 'plpgsql';

Will return correctly the value.

However I have a problem when the parameter can expect any type of data. I need to cast the parameter with NULL::

So the parsing will fail for this:

SELECT * FROM public.get_table(NULL::schema.tablename)

SELECT * FROM public.get_table(NULL:::P1)

Is there any way that the parameter can be set to not start with “:” or a way to add it in the function parameter but parsed correctly?

Community Page
Last updated: