简体   繁体   English

如何更正要在python中执行的sql查询?

[英]How to correct the sql query to execute in python?

I have one SQL query which I have to execute through python.我有一个必须通过 python 执行的 SQL 查询。 I have made connection with MYSQL but query format is not up to the mark.我已经与 MYSQL 建立了连接,但查询格式不符合要求。

Can you please help me to convert query in correct format for python.你能帮我将查询转换为正确的python格式吗?

query:询问:

select trim(CONCAT_WS('|',"Master Job Name","Seq","TableName","Source File Name Lnd","landingdfname","TargetPath","query1","Execution Sequence")) FROM DUAL

i ran the code-我运行了代码-

with db.cursor() as cur:
    query_meta = ("select trim(CONCAT_WS('|',Master Job Name,Seq,TableName,Source File Name Lnd,landingdfname,TargetPath,query1,Execution Sequence)) FROM DUAL")
    res = cur.execute(query_meta)
    res = cur.fetchall()

error -错误 -

pymysql.err.ProgrammingError: (1064, u"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 'Name,Seq,TableName,Source File Name Lnd,landingdfname,TargetPath,query1,Executio' at line 1")

Try the following:请尝试以下操作:

cursor.execute("select trim(CONCAT_WS('|','Master Job Name','Seq','TableName','Source File Name Lnd','landingdfname','TargetPath','query1','Execution Sequence')) FROM DUAL")

Query format is this:查询格式是这样的:

SELECT 
    CONCAT_WS(',', input_string1, input_string2,...)
FROM 
    table_name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM