在python中查询多个postgres表

问题描述 投票:0回答:1

我正在尝试查询多个sql表,并将它们存储为pandas数据框。

cur = conn.cursor()
  cur.execute("select relname from pg_class where relkind='r' and relname !~ '^(pg_|sql_)';")
  tables_df = cur.fetchall()
  ##table_name_list = tables_df.table_name 
  select_template = ' SELECT * FROM {table_name}'
  frames_dict = {}
  for tname in tables_df :
      query = select_template.formate(table_name = tname)
      frames_dict [tname] = pd.read_sql ( query , conn)

但是它给了我

   AttributeError: 'str' object has no attribute 'formate'

在线

    query = select_template.formate(table_name = tname)
sql python-3.x pandas postgresql psycopg2
1个回答
0
投票

根据您的错误,您似乎有一个错字字格式:

 AttributeError: 'str' object has no attribute 'formate'

尝试

query = select_template.format(table_name = tname)
© www.soinside.com 2019 - 2024. All rights reserved.