0

I am trying to get the mssql table column name and datatype using pyodbc

Here is my code:

def GetSQLTableFields(connDetails):
    cursor = conn.ConnectSQL(connDetails)
    cursor.execute("SELECT colum1, column2, column3 FROM TEST_TABLE")
    for col in cursor.description:
        print('name =', col[0], ', datatype =',col[1])
    cursor.close()

by using this code i'm not able to get the sql datatype of columns inseted i'm getting this

name = column1, datatype = <class 'str'>
name = column2, datatype = <class 'int'>

output i want

name = column1, datatype = nvarchar
name = column2, datatype = int
2
  • Does this answer your question? Get MSSQL table column names using pyodbc in python Commented May 18, 2020 at 11:38
  • No in the given example there is no datatype retrieval, and in my scenario the input is a sql query with mentioned column names not just a tableName Commented May 18, 2020 at 11:59

1 Answer 1

2

This is a long-standing feature request that has not been implemented in pyodbc itself.

https://github.com/mkleehammer/pyodbc/issues/167

You may want to try using the fork mentioned in that issue (if it is being maintained).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.