I have a function to delete those records withina given time period but I get an error while executing it.
10:58:23 [EXPLAIN - 0 row(s), 0.000 secs] [Error Code: 0, SQL State: 42883] ERROR: operator does not exist: date < integer
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Where: PL/pgSQL function delyearlyrecords(text) line 9 at EXECUTE statement
... 1 statement(s) executed, 0 row(s) affected, exec/fetch time: 0.000/0.000 sec [0 successful, 0 warnings, 1 errors]
please find below the function
Create Or Replace Function DelYearlyRecords (tablename TEXT) Returns integer as $$
Declare
Start_Date date;
End_Date date;
Begin
Start_Date = (current_date - interval '13 months')::date;
End_Date = current_date;
execute 'delete from ' ||tablename||
' where cast(date_dimension_year || ''-'' || date_dimension_month || ''-''||date_dimension_day as date)
not between '|| Start_Date ||' and '|| End_Date || ' ';
RETURN 1;
END;
$$ LANGUAGE plpgsql;
Thanks & Regards, Rajeev
DATE
column? – a_horse_with_no_name 9 mins ago