[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-help
Subject:    Re: [R] DBI::dbWriteTable syntax error apparently from quotes
From:       Eric Berger <ericjberger () gmail ! com>
Date:       2017-08-29 14:34:12
Message-ID: CAGgJW76g1KyUeq52XRAuv=xKSqJRZoRE28m7b7+-0NUaziKofQ () mail ! gmail ! com
[Download RAW message or body]

I did not put the double quotes in the SQL statement. The SQL statement was
created automatically by the routine dbWriteTable.
The full code (minus the details of creating the DBIConnection object)
would be like this, as in the man page for dbWriteTable

library(DBI)
library(odbc)
conn <- [connect to database]
DBI::dbWriteTable(conn,"mtcars",mtcars[1:5,])


The above code produces the error message in the OP




On Tue, Aug 29, 2017 at 4:43 PM, Jeff Newmiller <jdnewmil@dcn.davis.ca.us>
wrote:

> Double quotes are not legal SQL syntax. Use single quotes.
> --
> Sent from my phone. Please excuse my brevity.
>
> On August 29, 2017 2:21:44 AM PDT, Eric Berger <ericjberger@gmail.com>
> wrote:
> >I have been successfully using RODBC for a long time (years) to connect
> >to
> >MS SQL Server from R.
> >This week I wanted to try using odbc but I am seeing some problems
> >which
> >may be related to how I set up my driver and/or connection.
> >The dbWriteTable manual page gives as an example command:
> >
> >dbWriteTable( pDB$con, "mtcars", mtcars[1:5,])
> >
> >When I try this I get the following error
> >
> >Error: <SQL> 'CREATE TABLE "mtcars" (
> >  "row_names" varchar(255),
> >  "mpg" FLOAT,
> >  "cyl" FLOAT,
> >  "disp" FLOAT,
> >  "hp" FLOAT,
> >  "drat" FLOAT,
> >  "wt" FLOAT,
> >  "qsec" FLOAT,
> >  "vs" FLOAT,
> >  "am" FLOAT,
> >  "gear" FLOAT,
> >  "carb" FLOAT
> >)
> >'
> > nanodbc/nanodbc.cpp:1587: 42000: [FreeTDS][SQL Server]Incorrect syntax
> >near 'mtcars'.
> >
> >I believe that the complaint is related to the double quotes around
> >"mtcars" (and presumably the other double quotes in the command).
> >I tried searching to see if others have had this problem but I could
> >not
> >find anything.
> >
> >Thanks
> >
> >       [[alternative HTML version deleted]]
> >
> >______________________________________________
> >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide
> >http://www.R-project.org/posting-guide.html
> >and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic