Skip to content
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

to_sql doesn't seem to allow upload of df with some columns when the target table has a calculated column #60609

Open
qzoxec opened this issue Dec 26, 2024 · 2 comments

Comments

@qzoxec
Copy link

qzoxec commented Dec 26, 2024

I am trying to append a dataframe with several columns to a MS SQL table with a calculated field. I get the following error on attempt:
"sqlalchemy.exc.ProgrammingError: (pyodbc.ProgrammingError) ('42000', '[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The column "Fieldname" cannot be modified because it is either a computed column or is the result of a UNION operator. (271) (SQLExecDirectW); [42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Statement(s) could not be prepared. (8180)')"

This issue seems to have been addressed in the AWS sdk using the use_column_names parameter. See here - aws/aws-sdk-pandas#2170

That parameter doesn't seem to exist when using a sqlalchemy pyodbc connection. - "TypeError: to_sql() got an unexpected keyword argument 'use_column_names'"

Is there something similar that exists for a sqlalchemy pyodbc connection?

@Liam3851
Copy link
Contributor

In SQL Server, just not including the computed column in the dataframe you are passing through to_sql should work, assuming you're using if_exists='append' (I assume you must be because you have a computed column, which pandas would not create on its own).

@qzoxec
Copy link
Author

qzoxec commented Dec 28, 2024

@Liam3851 You are correct, I had an extra field in the df I was trying to pass. It works fine, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants