Reputation: 3006
How can I alter the type of a column in an existing table in MonetDB? According to the documentation the code should be something like
ALTER TABLE <tablename> ALTER COLUMN <columnname> SET ...
but then I am basically lost because I do not know which standard the SQL used by MonetDB follows here and I get a syntax error. If this statement is not possible I would be grateful for a workaround that is not too slow for large (order of 10^9 records) tables.
Note: I ran into this problem while doing some bulk data imports from csv files into a table in my database. One of the columns is of type INT but the values in the file at some point exceed the INT limit of 2^31-1 (yes, the table is big) and so the transaction aborts. After I found out the reason for this failure, I wanted to change it to BIGINT but all versions of SQL code I tried failed.
Upvotes: 2
Views: 1868
Reputation: 2562
This is currently not supported. However, there is a workaround:
Example table for this example, say we want to change the type of column b
from integer
to double
.
create table a(b integer);
insert into a values(42);
alter table a add column b2 double;
update a set b2=b;
alter table a drop column b;
alter table a add column b double;
update a set b=b2;
alter table a drop column b2;
Note that this will change the ordering of columns if there are more than one. However, this is only a cosmetic issue.
Upvotes: 4