Home > database >  How to drop the table with the date
How to drop the table with the date

Time:09-20

Every day I'm going to list A backup into A - 2019-06-30 (according to the date), the second day need to delete the previous day's backup table, that is to say, today is the 2019-07-01, need to delete A - the 2019-06-30 table, could you tell me how to write the SQL, you thank first

CodePudding user response:

Can use dynamic SQL statements in the PL/pgSQL:

 create table A_2019_06_29 int (id); 

Do $$
Declare
SQLSTR text;
The begin
SQLSTR:='drop table A_' | | to_char (current_date - 1, 'YYYY_MM_DD');
The execute SQLSTR;
End $$;

  • Related