Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6963469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:47:43+00:00 2026-05-27T15:47:43+00:00

I am trying to upload a data frame to a table in sql server

  • 0

I am trying to upload a data frame to a table in sql server using sqlSave(). This dataframe has a timestamp in it and I’d like to map the timestamp col to a datetime col in sqlserver.

I am getting two problems.

1. It maps the data frame’s timestamp to a float.
2. It creates a table, but no data is uploaded and I get an error.

Here’s an example data frame, mdf:

mdf <- structure(list(run = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("run_00", 
"run_01", "run_02", "run_03", "run_04"), class = "factor"), slot = structure(c(1L, 
1L, 1L, 1L, 1L, 1L), .Label = c("slot 3", "slot 4", "slot 5", 
"slot 6"), class = "factor"), timestamp = structure(c(1320774563, 
1320774624, 1320774686, 1320774747, 1320774809, 1320774871), class = c("POSIXct", 
"POSIXt"), tzone = ""), channel = structure(c(1L, 1L, 1L, 1L, 
1L, 1L), .Label = c("och01", "och02", "och09", "och10"), class = "factor"), 
    variable = structure(c(2L, 2L, 2L, 2L, 2L, 2L), .Label = c("num_blocks", 
    "num_collection", "num_corr_0", "num_corr_1", "num_uncorr_srow", 
    "post_fec_err_rate", "pre_fec_err_rate"), class = "factor"), 
    value = c(1, 62, 124, 185, 247, 309)), .Names = c("run", 
"slot", "timestamp", "channel", "variable", "value"), row.names = c(NA, 
6L), class = "data.frame")

> mdf
     run   slot           timestamp channel       variable value
1 run_00 slot 3 2011-11-08 12:49:23   och01 num_collection     1
2 run_00 slot 3 2011-11-08 12:50:24   och01 num_collection    62
3 run_00 slot 3 2011-11-08 12:51:26   och01 num_collection   124
4 run_00 slot 3 2011-11-08 12:52:27   och01 num_collection   185
5 run_00 slot 3 2011-11-08 12:53:29   och01 num_collection   247
6 run_00 slot 3 2011-11-08 12:54:31   och01 num_collection   309

Here’s what happens when I try sqlSave to a sql server database…

> sqlSave(dbandle,mdf,tablename="mdf")
Error in sqlSave(dbandle, mdf, tablename = "mdf") : 
  [RODBC] Failed exec in Update
22018 0 [Microsoft][ODBC SQL Server Driver]Invalid character value for cast specification

Also, when I look at the data types of the table, I don’t get “datetime” for the timestamp. It doesn’t make sense to me why RODBC would map a POSIXct timetamp to anything other than datetime.

[rownames] [varchar](255) NULL,
[run] [varchar](255) NULL,
[slot] [varchar](255) NULL,
[timestamp] [float] NULL,
[channel] [varchar](255) NULL,
[variable] [varchar](255) NULL,
[value] [float] NULL

How do I get around this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:47:44+00:00Added an answer on May 27, 2026 at 3:47 pm

    Two options:

    1) Lazy one: let the error occur, the table will be created, and change the column(s) to datetime manually in your database. It will work the next time.

    2) Correct: use varTypes

    Note that your problem can be stripped down by removing unnecessary stuff. As an aside, I probably would not use the column name timestamp in an sql server, because I have seen confusions because of the internal timestamp data type is totally different.

    library(RODBC)
    mdf = data.frame(timestamp=as.POSIXct(Sys.time()))
    
    varTypes = c(timestamp="datetime")
    channel = odbcConnect("test")
    sqlSave(channel,mdf,rownames=FALSE,append=TRUE,varTypes=varTypes)
    close(channel)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to upload data as multipart using RestClient like so: response =
I'm trying to upload some records to my local data store using appcfg.py Only
I am trying to upload an image to server using iphone . I haven't
I am trying to import data from a CSV file to a SQL Server
I am trying to upload file with like this: NSMutableDictionary * lParameters = [NSMutableDictionary
I'm trying to upload data onto a server. The server can accept strings of
I am trying to upload a File with one parameter using spring 3. This
I am trying to upload & retrieve data with the server. Which is the
I am trying to upload, download documents and spreadsheets using Google Documents List Data
I'm trying to upload some data to my App Engine datastore using the bulkuploader.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.