I'm trying to make a function to count the number of rows in a column. The objective is pass the table and the column as a parameter in a function and return the number of rows.
The function is:
CREATE OR REPLACE FUNCTION public.totalrecords(column_names text,table_names text)
    RETURNS bigint
    LANGUAGE 'plpgsql'
AS $BODY$DECLARE 
total integer;
BEGIN
    EXECUTE format('SELECT count(%s) into %I FROM %s', column_names,total,table_names);
    RETURN total;
END;$BODY$;
know anyone why doesn`t work? Any help is highly appreciated. Thanks in advance
 
    