0

As far as I know, standard Python DB api does not provide exact SQL type information of result rowset.

Is there anyway to get exact SQL type and some more detailed information like tinyint, bigint, nvarchar(100) for some result rowset rather than truncated python type like int, str ... ?

I think portability or module dependency is not important - something just work would be fine. (I'm working on windows, MS-SQL.)

1 Answer 1

1

Use .description after your query to retrieve information regarding your data-types amongst other things.

cursor.execute('select some_column from some_table')
print cursor.description

.description

        This read-only attribute is a sequence of 7-item
        sequences.  

        Each of these sequences contains information describing
        one result column: 

          (name, 
           type_code, 
           display_size,
           internal_size, 
           precision, 
           scale, 
           null_ok)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer, though 'description' member in cursor object does not provide exact SQL type information as my knowledge. (For example, there is no way to distinguish xml/nvarchar/varchar ...)

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.