Using python to reverse lookup field names in the data table

1. Data Links

import psycopg2

conn = psycopg2.connect(user,host,port,database,password)

cur = conn.cursor()

2. If you do not know the field names in the data table, you can get the field names in the table in the following ways

  We first need to obtain a pointer

  cur.execute('select * from your_table')

  print (cur.description) # console can print out all of the field names and field information in the table by this method

3. You can also check the relevant information table in one or a few fields

  The same also need to obtain the pointer

  cur.execute('select clomn_name1,clomn_name2 from table’)

  print (cur.description) # thereby obtain relevant information table, some fields

4. Finally, do not forget to close the database connection yo! ! !

  cur.close () # close the first pointer is connected

  conn.close () # finally close the database connection

 

Guess you like

Origin www.cnblogs.com/junG-Fjw/p/11165740.html