Is it possible to delete data stored in S3 through an Athena query? I have some rows I have to delete from a couple of tables (they point to separate buckets in S3).
I couldn't find a way to do it in the Athena User Guide: https://docs.aws.amazon.com/athena/latest/ug/athena-ug.pdf and DELETE FROM
isn't supported, but I'm wondering if there is an easier way than trying to find the files in S3 and deleting them.
You can leverage Athena to find out all the files that you want to delete and then delete them separately. There is a special variable "$path". To automate this, you can have iterator on Athena results and then get filename and delete them from S3.
To see a new table column in the Athena Query Editor navigation pane after you run ALTER TABLE ADD COLUMNS , manually refresh the table list in the editor, and then expand the table again. ALTER TABLE ADD COLUMNS does not work for columns with the date datatype.
In Normal practise using Athena we can insert or query data in the table, but the option to update and delete does not exist. With Apache Iceberg integration with Athena, the users can run CRUD operations and also do time-travel on data to see the changes before and after a timestamp of the data.
Your answer An alternative is to create the tables in a specific database. Dropping the database will then delete all the tables. CREATE DATABASE db1; CREATE EXTERNAL TABLE table1 ...; CREATE EXTERNAL TABLE table2 ...; DROP DATABASE db1 CASCADE; The DROP DATABASE command will delete the table1 and table2 tables.
You can leverage Athena to find out all the files that you want to delete and then delete them separately. There is a special variable "$path".
Select "$path" from <table> where <condition to get row of files to delete>
To automate this, you can have iterator on Athena results and then get filename and delete them from S3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With