Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
- COLUMN_NAME DATA_TYPE PK NULLABLE DEFAULT AUTOINCREMENT COMPUTED REMARKS POSITION
- col1 varchar(10) YES NO NO NO 1
- col2 varchar(50) NO NO NO NO 2
- col3 smallint NO NO NO NO 3
Add Comment
Please, Sign In to add comment