SQL function not working when trying to write table to non-default schema

前端 未结 3 2020
情话喂你
情话喂你 2021-01-14 22:07

I am trying to write a table to a non-default schema in SQL Server 2017. I am using RStudio\'s documentation as to what the best practice is for doing this: https://db.rstud

相关标签:
3条回答
  • 2021-01-14 22:18

    DBI 1.1.0 overcomes this issue.

    dbWriteTable(con, SQL("schema.newTbleIris"), iris)
    
    0 讨论(0)
  • 2021-01-14 22:30

    In my case, doing dbWriteTable(con, "[schema].newTbleIris", iris) without wrapping any function around worked.

    0 讨论(0)
  • 2021-01-14 22:31

    I've found an easy workaround for this. Just follow through these steps:

    First, write your table with a default schema: dbWriteTable(con, "newTbleIris", iris)

    And insert it into a new one with a non-default schema, but this time using the dbGetQuery function:

    dbGetQuery(con, "SELECT * INTO [schema].newTbleIris FROM newTbleIris")

    And that's it! Your table will now appear with a non-default schema.

    Now you can remove the first table you first created with a default schema by doing dbGetQuery(con, "DROP TABLE newTbleIris")

    0 讨论(0)
提交回复
热议问题