Column length not returned for NVARCHAR columns when inspecting a HANA Cloud view
JanFetzer opened this issue · comments
JanFetzer commented
Hi,
I am using sqlalchemy.engine.reflection.Inspector to relect view column of a database view in HANA Cloud.
inspector = reflection.Inspector.from_engine(engine)
colTypes = inspector.get_columns(table_name="myView", schema="mySchema")
while the view actually has fields id & user of data type NVARCHAR with length =5000 and 255 respectively, what I get for colTypes is
[{'name': 'id',
'default': None,
'nullable': True,
'comment': None,
'type': NVARCHAR()},
{'name': 'user',
'default': None,
'nullable': True,
'comment': None,
'type': NVARCHAR()}]
The SQL generated is this (I inspected it with echo=True when creating the engine object):
SELECT COLUMN_NAME, DATA_TYPE_NAME, DEFAULT_VALUE, IS_NULLABLE, LENGTH, SCALE, COMMENTS FROM (
SELECT SCHEMA_NAME, TABLE_NAME, COLUMN_NAME, POSITION, DATA_TYPE_NAME, DEFAULT_VALUE, IS_NULLABLE,
LENGTH, SCALE, COMMENTS FROM SYS.TABLE_COLUMNS UNION ALL SELECT SCHEMA_NAME, VIEW_NAME AS TABLE_NAME,
COLUMN_NAME, POSITION, DATA_TYPE_NAME, DEFAULT_VALUE, IS_NULLABLE, LENGTH, SCALE, COMMENTS FROM
SYS.VIEW_COLUMNS) AS COLUMS WHERE SCHEMA_NAME=? AND TABLE_NAME=? ORDER BY POSITION
and it correctly contains the column length (see screenshot), but the information gets lost while passing it on to SQLAlchemy.
As a result, I cannot e.g. generate a table with same column type specification, since if I specify its column dtypes as NVARCHAR(), the default field length is 1, and my data will not fit