Using a dictionary to pass parameters to postgresql statement in python
问题 I have defined a dictionary which contains several parameters and their values which will ultimately be used to build a SQL Query query_params = collections.OrderedDict( {'table_name':'publilc.churn_data', 'date_from':'201712', 'date_to':'201805', 'class_target':'NPA' }) The parameters are to be used in the below query: sql_data_sample = str("""select * from %s # get value of table_name where dt = %s #get value of date_from and target in ('ACTIVE') --------------------------------------------