This post seems to be similar but, there, a user points out "long" is a reserved key. So I think even that reserved key is causing some problem, and asking this as new question.
I need to use back-tick inside shell script to execute MySQL query. The database name contains "hyphen" in it. To treat the whole DB name as one I've enclosed it inside back-tick. But shell script uses back-tick for command substitution. So I escaped back-tick with "\". Below is the result.
CREATE TABLE reporting.details AS SELECT * FROM \`Temp-17-09-19\`.details;
But I'm getting the below error.
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'Temp-17-09-19.details' doesn't exist
It has considered the whole "db-name.table_name" (Temp-17-09-19.details) as "table" itself. I'm not getting why back-ticks are removed while executing query even after escaping them. Here my context of escaping the back-tick is only from shell script not MySQL query.
Is it doable?
Update: As asked by @shellter, below is the full shell script. And shellter, enclosing the whole query in single quote also giving same error. Also replacing back-tick with single quote is giving MySQL syntax error.
#!/bin/sh
cd `dirname $0`
ROOT_PATH=`pwd`
java -Dtalend.component.manager.m2.repository=$ROOT_PATH/../lib -Xms256M -Xmx1024M -cp .:$ROOT_PATH:$ROOT_PATH/../lib/routines.jar:$ROOT_PATH/../lib/activation.jar:$ROOT_PATH/../lib/crypto-utils.jar:$ROOT_PATH/../lib/dom4j-1.6.1.jar:$ROOT_PATH/../lib/log4j-1.2.17.jar:$ROOT_PATH/../lib/mail-1.4.jar:$ROOT_PATH/../lib/mysql-connector-java-5.1.30-bin.jar:$ROOT_PATH/projtablesync_0_1.jar: local.projtablesync_0_1.projTableSync --context=Default --context_param Email_To="[email protected]" --context_param Email_From="[email protected]" --context_param Email_Cc="[email protected]" --context_param smtp="smtp.gmail.com" --context_param processName="Tag" --context_param dropTempTableQry="drop table if exists reporting.details;" --context_param createTempTableQry="CREATE TABLE reporting.details AS SELECT * FROM \`Temp-17-09-19\`.details;" --context_param updateFinalTableQry="UPDATE reporting.details AS a INNER JOIN reporting.details AS b ON a.tag_id = b.tag_id AND a.seq_id = b.seq_id SET a.tag_submit_date = b.tag_submit_date, a.tag = b.tag, a.tag_update_date = b.tag_update_date, a.fail_code = b.fail_code, a.is_priority = b.is_priority, a.mobile_platform = b.mobile_platform, a.status = b.status, a.target_countries = b.target_countries, a.content_type = b.content_type, a.status_code = b.status_code, a.status_code_description = b.status_code_description;" --context_param insertFinalTableQry="INSERT INTO reporting.details SELECT a.* FROM reporting.details AS a LEFT JOIN reporting.details AS b ON a.Seq_id = b.Seq_id AND IFNULL(a.tag_id, \"\") = IFNULL(b.tag_id, \"\") WHERE b.seq_id IS NULL;"
Thank you.
SELECT sysdate() from DUAL;(or the MySQL equivalent)? As I no longer have access to mySQL or any commercial DB, I won't be able to experiment further on your problem. I'd recommend changing your[shell]tag to[bash]as you'll get many more readers that search for[bash]questions. Good luck.--context_param createTempTableQry="CREATE TABLE reporting.details AS SELECT * FROM \`Temp-17-09-19\`.details;". Thank you for suggesting [bash] tag. Will add that too.