Search code examples
mysqlquartz-scheduler

Escaping hyphen in MySQL query (not using a backtick)


We have an existing schema we're trying to fit some quartz tables into, but the tables are named with hyphen in them, so we'd like to use a prefix like "08-Scheduling_QUARTZ_"

Since quartz doesn't wrap any of the queries in back ticks, the prefix doesn't work.

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '08-Scheduling_QUARTZ_TRIGGERS SET TRIGGER_STATE = 'WAITING' WHERE SCHED_NAME' at line 1]]

Curious if there is any chance there is some other way to escape the "-" in a mysql query other than `` around the whole table name?

I've tried

x'-'x

x\-x

x"-"x

x`-`x


Solution

  • No, you must delimit the identifier if it has certain punctuation characters.

    In MySQL, the default identifier delimiter is the back-tick.

    If you enable the ANSI or ANSI_QUOTES SQL modes, you can use double-quotes as an identifier delimiter.

    If you don't want to use delimiters, you must choose a different convention for prefixing your table names. You could use _ for example.

    Read https://dev.mysql.com/doc/refman/8.0/en/identifiers.html for more details on the characters permitted in identifiers without delimiters.