How can I rename a table in monetdb?
The typical SQL statement ALTER TABLE name RENAME TO new_name
is not supported.
Asked
Active
Viewed 1,923 times
4
-
2maybe `CREATE TABLE newname AS SELECT * FROM oldname WITH DATA; DROP TABLE oldname;` ? – Anthony Damico Oct 30 '13 at 03:10
-
^is correct solution. [I have tried renaming system db entries failed and you don't want to do that] – Gaurav Oct 30 '13 at 07:40
-
1I have tried `CREATE TABLE newname AS SELECT * FROM oldname WITH DATA; DROP TABLE oldname;` and it works. Thanks. – pic Nov 01 '13 at 09:54
-
@pic, please accept Lin_n's answer. – einpoklum Jan 27 '21 at 11:07
2 Answers
2
Also consider creating a SQL view with the new name, e.g. CREATE VIEW newname AS SELECT * FROM oldname;
This has the advantage of no data being copied around at all.

Hannes Mühleisen
- 2,542
- 11
- 13
-
hi hannes - is there a similar approach for renaming columns? from what I found on the monetdb mailing lists it seems like the `rename column` syntax is not supported [1](https://www.monetdb.org/bugzilla/show_bug.cgi?id=2478)/[2](https://www.monetdb.org/pipermail/users-list/2009-February/002551.html). namely - got a column named `Key` which somehow got mangled throuh `monet.read.csv()` into `ï..Key`. (p.s. `monetdblite`) – davidski Jan 11 '17 at 14:35
2
ALTER TABLE [ IF EXISTS ] [ schema_name . ] table_name RENAME TO new_table_name
It's supported since 2019 MonetDB website

Lin_n
- 189
- 1
- 4