我希望使用python代码获取数据,就像我们对describe [tableName] statement
所做的那样。我想在Redshift和DB2上这样做。在
我尝试使用Pandas和cursor来实现这一点,我尝试了以下命令块:
"set search_path to SCHEMA; select * from pg_table_def where schemaname = 'schema' and LOWER(tablename) = 'TableName';
describe schema.tableName
select column_name, data_type, character_manimum_length from information_schema.columns where table_schema = 'Schema' and table_name = 'TableName';
\d or \d+
一。在
import psycopg2
import numpy as np
import pandas as pd
con=psycopg2.connect(dbname= 'DBNAME', host="Host-Link",
port= '5439', user= 'username', password= 'password')
print(con)
cur = con.cursor()
query = "set search_path to Schema; select * from pg_table_def where schemaname = 'Schema' and LOWER(tablename) = 'TableName';"
cur.execute(query)
temp = cur.fetchall()
print(temp)
data_frame = pd.read_sql("set search_path to Schema; select * from pg_table_def where schemaname = 'Schema' and LOWER(tablename) = 'TableName';", con)
print(data_frame)
con.close()
我希望输出如下:
^{pr2}$
很多数据都包含在
SVV_COLUMNS
系统视图中。您可以使用table_name
和table_schema
列查询该表。在https://docs.aws.amazon.com/redshift/latest/dg/r_SVV_COLUMNS.html
相关问题 更多 >
编程相关推荐