Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Is there a way to get Python types from SQL column types? #1200

Unanswered
ysur67 asked this question in Q&A
Discussion options

Hello!

I've been developing a system with dynamically created SQL queries. Now, I need to determine the types of columns based on the types presented in the query result.

I am using asyncpg as a driver and SQLAlchemy as an ORM. I've managed to get database type codes from the asyncpg result using properties on SQLAlchemy's cursor like this:

for column_name, db_api_type_code, *_rest in result.cursor.description:

The .description property gives me tuples like the following:

>> ('id', 1043, None, None, None, None, None)
>> ('name', 1043, None, None, None, None, None)

Now, I would like to know if there is a way to get Python types from known DB type codes without creating my own dictionary, where the key is the type code and the value is the corresponding Python type.

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /