There is a column named "column" in table "table", but it cannot be referenced from this part of the query

Viewed 7375

so im trying to enter data from a python dictionary into a postgres database using a for loop.Heres the code

for value in dic:
    domain_desc = value["domain_desc"]
    commodity_desc = value["commodity_desc"]
    statisticcat_desc = value["statisticcat_desc"]
    agg_level_desc = value["agg_level_desc"]
    country_name = value["country_name"]
    state_name = value["state_name"]
    county_name = value["county_name"]
    unit_desc = value["unit_desc"]
    value1 = value["Value"]
    year_val = value["year"]
    cur.execute("INSERT INTO fact_data (domain_desc,commodity_desc,statisticcat_desc,agg_level_desc,country_name,state_name,county_name,unit_desc,value,year) VALUES (domain_desc,commodity_desc,statisticcat_desc,agg_level_desc,country_name,state_name,county_name,unit_desc,value1,year_val)")
    cur.commit()
    print("Success!")

I keep getting the error

Traceback (most recent call last): File "C:/Users/Backup/PycharmProjects/gro-app/harvest.py", line 123, in cur.execute("INSERT INTO fact_data (domain_desc,commodity_desc,statisticcat_desc,agg_level_desc,country_name,state_name,county_name,unit_desc,value,year) VALUES (domain_desc,commodity_desc,statisticcat_desc,agg_level_desc,country_name,state_name,county_name,unit_desc,value1,year_val)") psycopg2.ProgrammingError: column "domain_desc" does not exist LINE 1: ...te_name,county_name,unit_desc,value,year) VALUES (domain_des... ^ HINT: There is a column named "domain_desc" in table "fact_data", but it cannot be referenced from this part of the query.

I have the database and the table in the right place. What is causing this error? I have found a similar question but i dont understand the error and its in a different context Someone help me understand this

1 Answers
Related