October 24, 2024
Chicago 12, Melborne City, USA
SQL

Updating dataset in mysql database


I am running a mysql command within a tool to update a file on a database. I have the following command in place:

arguments=["-c", """
    if ! awk '{ 
        system("mysql --host website.cloud --user xxxx --password=xxxx database -e \\"UPDATE test_dataset SET SampleName="\"'"$2"'\'' WHERE SampleName="\"'"$1"'\'';\\"") 
    }' /data/correct_name.txt; then
        echo "Error updating MySQL database"
    fi
"""]

But I am continuously getting the following error message after each line:

ERROR 1064 (42000) at line 1: 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 'WHERE SampleName=" at line 1

I put the above argument in an Airflow DAG. The following code worked when it was used within the source code of a tool, but the problem occurred when I put the code in the Airflow.

if ! awk "{ system("mysql --host database.cloud --user sss --password=sss database -e \"UPDATE test_dataset SET SampleName="\"'"$2"'\'' WHERE SampleName="\"'"$1"'\'';\"") }' /data/corrected_data.txt
then
    echo "Error updating MySQL database"
fi

Could you please help to fix this issue?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video