'''
host = "localhost"
user = "postgres"
password = "Lall1739!@#"
port = "5432"
dbname = "snp500"
con_form = "host={0} user={1} password={2} port={3} dbname={4}".format(host, user, password, port, dbname)
con = psycopg2.connect(con_form)
cur = con.cursor()
components_name, components_prices, components_fetch_dates = fetch_investing_snp500_components_datas()
for component_name in components_name:
table_name = component_name
cur.execute(
query=sql.SQL("CREATE TABLE %s"),
vars=(sql.Identifier(table_name))
)
'''
TypeError: 'Identifier' object does not support indexing
It's also not a good idea to use Python string interpolation to build the query string.
So I am trying to write a query using the sql module.
What exactly are the benefits of writing a query using the sql module and why am I getting a Type error?
sqlin your code?sqlispsycopg2.sql.