SQLAlchemy accessing column types from query results
If no, is it possible to get the SQL data types?
SQL Server function sys.dm_exec_describe_first_result_set could be used to get SQL column's data type directly for provided query:
SELECT column_ordinal, name, system_type_name, *
FROM sys.dm_exec_describe_first_result_set('here goes query', NULL, 0) ;
In your example:
sql = """SELECT column_ordinal, name, system_type_name
FROM sys.dm_exec_describe_first_result_set('SELECT * FROM FAKETABLE', NULL, 0) ;"""
For:
CREATE TABLE FAKETABLE(id INT, d DATE, country NVARCHAR(10));
SELECT column_ordinal, name, system_type_name
FROM sys.dm_exec_describe_first_result_set('SELECT * FROM FAKETABLE', NULL, 0) ;
+-----------------+----------+------------------+
| column_ordinal | name | system_type_name |
+-----------------+----------+------------------+
| 1 | id | int |
| 2 | d | date |
| 3 | country | nvarchar(10) |
+-----------------+----------+------------------+
db<>fiddle demo