Python Forum
How read Table Structure from Database - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How read Table Structure from Database (/thread-14535.html)



How read Table Structure from Database - nnsatpute - Dec-05-2018

Hello,

I want to read the table description for particular table database and create the hive QL (HQL) statement
to create table in Hive using python code.

Can anyone please help how this can be achieved.

Thanks,


RE: How read Table Structure from Database - Larz60+ - Dec-05-2018

you didn't say the DBMS name.
Most have a way to display the schema.
If sqlite3:
install sqlite3, on Linux Mint, use:
sudo apt install sqlite3
You will have to look up command for other systems, see: https://sqlite.org/download.html

from command line:
  • sqlite3 yourdbname
  • sqlite> .output 'schema.txt'
  • sqlite> .schema
  • sqlite> .quit



RE: How read Table Structure from Database - nnsatpute - Dec-05-2018

I want to handle it in script data base will be anyone Oracle,Mysql.

Script should connect to database and fetch the table structure of table which is passed in script


RE: How read Table Structure from Database - Gribouillis - Dec-05-2018

A few years ago, I wrote a small script to print the structure of an sqlite database from python. I hope it helps.


RE: How read Table Structure from Database - hemasri - Oct-25-2019

Hi All...
I am trying to make a list from the table values I retrieved using below method
Code:

tabledata=browser.get_table_data("Xpath__//div[@class='col-md-12 hui-display']/div/div")
#print("printing table data")
#print(tabledata)
if(len(tabledata)>0):
import pandas as pd
pd.set_option('display.max_columns',None)
table_df=pd.DataFrame(tabledata)
print("printing the data frame")
print(table_df)

I am getting data in a not so defined formatt

How do I get data from a table with all the header and keep it in a list to compare it with my test data. Please help me out understand this


RE: How read Table Structure from Database - Larz60+ - Oct-25-2019

hemasri ... Please start your own thread.
Your post has nothing to do with this thread and doesn't belong here.