Passing arguments to the sql query

I have tried the below commands and it got worked.

prgname=sys.argv[0]
county=sys.argv[1]
city=sys.argv[2]
area=sys.argv[3]
pin=sys.argv[4]
date=sys.argv[5]

    postgreSQL_select_Query = "select UPPER(name) from list_name where country= %s and city= %s "
    cursor.execute(postgreSQL_select_Query,(country,city)
    mobile_records = cursor.fetchall()


    postgreSQL_select_Query2 = "select distinct(CONCAT('ddd_',a.country,'_',a.city,'_',a.area,'_TCF_L00',num,'_',area,'_%s_%s.csv')) as INPUT_FILE from file a  JOIN prod b  ON a.area = b.area and a.city = b.city and a.country = b.country where a.country= %s and a.city= %s and a.area= %s ",(country, city, area, pin, date)
    cursor.execute(postgreSQL_select_Query2,(country,city,area,pin,date)
    mobile_records2 = cursor.fetchall()

If i try to pass the code and date values in the sql query. i am getting error.

 prgname=sys.argv[0]
ctry=sys.argv[1]
city=sys.argv[2]
area=sys.argv[3]
code=sys.argv[4]
date=sys.argv[5]

 
 postgreSQL_select_Query2 = "select distinct(CONCAT('DDD_',a.ctry,'_',a.city,'_',a.area,'_FC_SSS',
 hierarchy_num,'_',file_code,'_%s_%s.csv')) as INPUT_FILE from file_types a  JOIN prod b  ON a.area = b.area 
 and a.city = b.city and a.ctry = b.ctry where a.ctry= %s and a.city= %s and a.area= %s "


cursor.execute(postgreSQL_select_Query2, (code, date, ctry, city, area))

Receiving the output as : DDD_EU_CHENNAI_ALANDUR_FC_SSS01_WEIGHT_'SD'_'2023'.csv

Expected output

 DDD_EU_CHENNAI_ALANDUR_FC_SSS01_WEIGHT_SD_2023.csv

Can you let me know how to remove the single quote in the sql output

Your query string has '_%s_%s.csv' which is coming out as _'SD'_'2023'.csv. As those parameters are strings, this suggests that it’s inserting them quoted, which isn’t surprising. Therefore, change that part of the query string to take that into account by writing '_',%s,'_',%s,'.csv'.