I'm trying to write a PL/pgSQL function with a VARCHAR argument, which should be limited. Consider following function, with a VARCHAR parameter limited to a size of 5 characters:
CREATE OR REPLACE FUNCTION do_nothin(v_value VARCHAR(5))
RETURNS TEXT AS
$$
DECLARE
BEGIN
RETURN v_value;
END;
$$
LANGUAGE plpgsql;
When I call this function with a text bigger than 5, it does work:
DO $$
DECLARE
BEGIN
PERFORM do_nothin('123456');
END;
$$
It gives me the result '123456', but why? This should give me an error right?
If I define a varchar like this:
DO $$
DECLARE
v_mytext VARCHAR(5);
BEGIN
v_mytext := '123456';
END;
$$
it gives me an error as expected:
ERROR: value too long for type character varying(5) CONTEXT: PL/pgSQL function inline_code_block line 5 at assignment SQL state: 22001
I want this error thrown when there is a too big argument for the function, but how?