Create Or Replace Function totalRecords (tablename TEXT) Returns integer as $total$
    Declare
      total integer;
      Begin
       select count  (*)  into  total  from''|| tablename ||' 'where now() - cast(date_dimension_year||'-'||date_dimension_month||'-'||date_dimension_day AS date) < INTERVAL '3 months' ;
        RETURN total;
       END;
$total$ LANGUAGE plpgsql;
i have a task which is to create a function which checks the DB for records on given condition if satisfied should output the result to a text file.The above pasted code is what i have been playing around with no sucess.I get syntax error....could anyone guide me on this? I am using postgres DB.
