1

In a bit of a pickle, I have somehow managed to get a typo applied to a column name and for this database, I have only CLI access, which is not allowing me to escape out the single apostrophe in the column name to apply a DROP COLUMN statement to it:

ALTER TABLE mytable DROP COLUMN 'my_typod_column;

I have tried wrapping the column in double quotes, doubling up the single quote and using a backslash, to no avail.

My next attempt to solve it will be to create a temporary table from this one, cherry-picking all but this column, then replacing the current table with it, but is less desirable. Hoping for a solution to escape the single quote on CLI instead.

Environment info

mysql Ver 14.14 Distrib 5.7.19, for Linux (x86_64) using EditLine wrapper

bash

Community
  • 1
  • 1
ljs.dev
  • 4,271
  • 2
  • 45
  • 79
  • 1
    Possible duplicate of [When to use single quotes, double quotes, and backticks in MySQL](https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks-in-mysql) – axiac Sep 15 '17 at 10:18
  • Did backticks work for you? – Manav Sep 15 '17 at 10:20

2 Answers2

1

Have you tried backticks?

ALTER TABLE mytable DROP COLUMN `'my_typod_column`;
Gordon Linoff
  • 1,198,228
  • 53
  • 572
  • 709
1

You can try wrapping your column name in backticks

ALTER TABLE mytable DROP COLUMN `'my_typod_column`;

:)

Manav
  • 1,297
  • 10
  • 17