'Is there a way to iterate through list and get row and column count of multiple Redshift tables using Python?

I am trying to get row and column count for tables that are present in different schemas in Redshift using Python's redshift_connector. I tried below code and receiving Programming Error that says. Not sure what is the issue ? Basically, I am trying to replace the shema and tables that are present in the list tables and get row count for the tables.

{'S: 'ERROR','C':123489, 'M' 'Syntax error at or near "{"",'P':'22....'L':714','R':'yyerror'}

Thanks in advance for your time and efforts!

Python Code:

import redshift_connector

tables=['schema1.tablename','schema2.table2']

conn=redshift_connector.connect(
    host='my_host',
    port= "my_port",
database='my_db'
user="user"
password='password')

cur=conn.cursor()
cur.execute ('select count(*) from {',' .join("'"+y+"'" for y in tables)}')
results=cur.fetchall()
print("The table {} contained".format(tables[0]),*result[0],"rows"+"\n" ) #Printing row counts along with table names

cur.close()
conn.close()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source