-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DataFrame.to_sql generated text field that could not be used by "group by". (MS sql) #7957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@NathanielCapital Did it work without specifying a max length? (so with For strings it seems indeed better to use |
@jorisvandenbossche Yes, it works without specifying a max length. I just made it return String type other than Text. The table text field generated is nvarchar(max) on my Microsoft SQL 2008 R2. |
@jorisvandenbossche Text is deprecated in the SQL Server, and has limited functionality. (see links below) Nvarchar and varchar types are preferable. Since this may vary between SQL flavors, perhaps there could be a setter function to set the string representation in pandas.io.sql.PandasSQLTable._sqlalchemy_type. http://msdn.microsoft.com/en-us/library/ms187993.aspx |
@aergener it would be better to avoid requiring setters like this - I'm confident we can get this to work without encouraging hacks, though anyone who really wants to change behaviour is free to subclass PandasSQLTable and override whatever they like. Seems there are 2 options: As well as explicitly setting nvarchar etc. (NVARCHAR is automatically subclass of Unicode it seems). Personally I like the idea of using Unicode since it fits well with Python3 going forwards where people expect all text to be unicode. Not sure what that means for python2 however, might then require explicit conversion so it might not be worth the trouble :/ |
I read in the SQLAlchemy docs (http://docs.sqlalchemy.org/en/rel_0_9/core/types.html#sqlalchemy.types.Unicode):
In that case, it seems to me that we should use |
With |
careful as this must scan all data |
@jreback yes, but we already do this .. (if it is an object type column, to check for date/time: https://github.com/pydata/pandas/blob/master/pandas/io/sql.py#L788) |
@jorisvandenbossche right ok |
Problem with changing
which is what is actually also explained in the sqlalchemy docs of |
I know this does not solve the issue, but after PR #8926, you can specify a sqlalchemy type per column, so to override the default chosen one. So at least that gives a way to deal with this issue for now. |
In
_sqlalchemy_type
function, pandas import Text type from sqlalchemy as the default type when generating text field in SQL table, which is transformed into "text" type in microsoft sql. This type could not be used by "group by" in SQL query.SQL query with a group by clause with the field generate an error msg like:
Msg 306, Level 16, State 2, Line 3
The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.
I tried default text field to be the
String
, which works for MS sql.The text was updated successfully, but these errors were encountered: