0

I couldn't remane my column if it existed, this is what i tried (i'm adding the different lines tested in same ALTER my_table to summarize) :

ALTER TABLE my_table
  RENAME IF EXISTS column_name TO column_name_new;
  RENAME IF EXISTS column_name column_name_new;
  RENAME COLUMN column_name TO column_name_new;
  RENAME COLUMN column_name column_name_new;

everything returned me this error : ALTER TABLE my_table RENAME COLUMN column_name TO column_name_new Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COLUMN column_name TO column_name_new' at line 2 0.000 sec

Brice B
  • 103
  • 1
  • 1
  • 8

1 Answers1

0

https://mariadb.com/kb/en/alter-table/ using this as the reference, I found that RENAME (COLUMN) IF EXISTS well doesn't exist.

This is the solution present in the documentation :

 CHANGE [COLUMN] [IF EXISTS] old_col_name new_col_name column_definition [FIRST|AFTER col_name]

Example that worked :

ALTER TABLE my_table
  CHANGE COLUMN IF EXISTS column_name column_name_new TYPE DEFAULT VALUE;

This code can be reexecuted without error, tested with mariaDB 10.3.

Brice B
  • 103
  • 1
  • 1
  • 8