Closed aklaver closed 9 years ago
This is correct, I've currently only added support for the most generic SQL types. I'd love it if somebody wanted to add the other type support!
I can take a run at this. A little playing around got the below to work. I added TEXT to the char types also. This is a ways from a patch, but it is a proof of concept for comparing apples to apples, i.e. the underlying Python type.
for sql_column in sql_table.columns: column_names.append(sql_column.name) sql_type = type(sql_column.type) py_type = sql_column.type.python_type dt = DATETIME()
if sql_type in [BIGINT, DECIMAL, FLOAT, INTEGER, NUMERIC, REAL, SMALLINT]:
column_types.append(agate.Number())
elif sql_type is BOOLEAN:
column_types.append(agate.Boolean())
elif sql_type in [CHAR, NCHAR, VARCHAR, NVARCHAR, TEXT]:
column_types.append(agate.Text())
elif sql_type is DATE:
column_types.append(agate.Date())
elif py_type is dt.python_type:
column_types.append(agate.DateTime())
else:
raise ValueError('Unsupported sqlalchemy column type: %s' % sql_type)
See PR #5.
Agate conversions are now based on sqlalchemy's Python type, so theoretically all SQL types are now supported. (Except for time deltas, see #2.)
agate==1.0.0 agate-sql==0.2.0
Seems database specific types are not supported.
In [1]: import agate
In [2]: import agatesql
In [3]: agatesql.patch()
In [4]: plants = agate.Table.from_sql('postgresql://postgres:@localhost/production', 'plant1')
ValueError Traceback (most recent call last)