-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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 if_exists argument with SQL server and other schema #7422
Comments
@aergener How did you connect to SQL server (how do you set the default schema)? It is a bit strange that when checking for the table it looks in |
@jorisvandenbossche I connected to SQL Server using |
Can you check |
When the table is in the
When creating a table in SQL Server if a schema is not specifically designated, the table will be created in the user's default schema. Perhaps this issue could be fixed if pandas specified a schema for sqlalchemy to use that the user could potentially override? |
I cannot reproduce this with postgresql (set the default schema to something else than the default 'public', but both the checking if the table exists or writing the data uses the same schema I set as default). So I am thinking it is possibly a bug in the sqlalchemy interface to SQL server (just guessing, I don't use SQL server). As |
@aergener I posted on the sqlalchemy mailing list: https://groups.google.com/forum/?fromgroups#!topic/sqlalchemy/Ktu06z9x97c Can you try what is said there? So add |
@jorisvandenbossche Cool, I'll test this out then get back to you. As an aside, I was wondering if you have thought about adding better datatype support to pandas. Specifically, looking at |
@jorisvandenbossche It looks like it's not picking up anything for the
|
@aergener Hmm I don't know SQL Server, so don't know how it works with users and schema's. Maybe you follow up further at the sqlalchemy mailing thread? |
Sounds related to #7441 -- @jorisvandenbossche, looks like we'll need to be able to pass schema/meta manually to @aergener Try this? engine = create_engine(..., echo='debug')
meta = MetaData()
meta.reflect(bind=engine, schema='test') |
@aldanor It is certainly related, but not necesarily the same issue, as 1) this just works with postgresql (if you are a user with another default schema, it just reads and writes from/to that schema), and 2) I mean, having a UPDATE: my second point can of course be solved with the |
@jorisvandenbossche Can't say much about this case, don't know much about SQL Server either. In Oracle, I had to set the schema equal to original table owner when calling Regarding the original question, found a discussion on schemas in sqlalchemy with SQL Server here: https://groups.google.com/forum/#!topic/sqlalchemy/VZQ_SLprNQA -- again, it boils down to passing schema manually when all else fails. Looks like there's many ways "default schema" could fail, quoting the link above:
|
@aergener If you want to get more involved, very welcome! I am following up a bit the sql issues, but I am by no mean an sql expert (just using postgresql a bit myself). So the experience of other people with other database flavors, more advanced use cases, other database set-ups with users and privileges, etc is very useful.
See here for more general advice on getting started with pandas development: http://pandas.pydata.org/developers.html and https://github.com/pydata/pandas/wiki/Contributing. If you have any questions, just ask here or at the pydata mailing list (https://groups.google.com/forum/#!forum/pydata). Questions you have are probably also relevant to others. |
I have also problems with the missing
On the other hand the
So when I call:
Am I correct that this is kind of the same problem as you discussed? |
They're related, and down to the fact that
imho the entry methods (e.g. |
What do think about replacing the two functions in
with:
of course at many other points schema_name would have to be added to function call |
@jorisvandenbossche I will try this out and get back to you |
The
if_exists
argument of theto_sql
function doesn't check all schema for the table while checking if it exists. Furthermore, it inserts to the default schema, causing somewhat contradictory behavior.For example, while using SQL Server with my default schema set to
test
,to_sql
inserts the table intotest.table_name
. However, trying this again, withif_exists='replace'
,to_sql
finds no table of the namedbo.table_name
, and then tries to createtest.table_name
, causing an error.Details :
http://stackoverflow.com/questions/24126883/pandas-dataframe-to-sql-function-if-exists-parameter-not-working
The text was updated successfully, but these errors were encountered: