Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename a table in Athena?

probably a very trivial question but I'm not sure about this and also don't want to lose the table. How do I rename a table in Athena?

Database name - friends
table name - centralPark
desired table name -centralPerk
like image 891
Dawson Smith Avatar asked Oct 21 '25 15:10

Dawson Smith


2 Answers

you can't!

see the list of unsupported DDL in Athena.

what you can do is to make a new table using select:

CREATE TABLE centralPark
AS SELECT * FROM centralPerk
WITH DATA

and drop the old table:

DROP TABLE IF EXISTS centralPerk
like image 160
eshirvana Avatar answered Oct 23 '25 03:10

eshirvana


I know this is old, but for new people that seek the answer I'll write anyway.

There's no single command but you can do it easily with 2, either manually or programatically. You do

show create table `your_table`

Then copy-paste the "create external table" command to the editor, replace table name and run.

If the table includes non-projection partitions, you will also need to run this to detect and load your partitions.

MSCK REPAIR TABLE `your_table`

You can do the same programmatically by doing simple regexp replace of the table name and rerun. It's more complicated of course than running "CREATE TABLE ... AS SELECT ..." but it's immediate, free and will promise the same structure pointing to the same place in S3.

like image 32
Kaplan Ilya Avatar answered Oct 23 '25 04:10

Kaplan Ilya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!