You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The SQL Server DATETIMEOFFSET field is not recognized and/or formatted correctly. Instead of a "usable" timezone, it's including a rather-verbose version: "2018-08-16 23:14:18 Pacific Standard Time". I can't find it anywhere in the source for odbc or DBI, though I do find it in the R source extra/tzone/registryTZ.c. I know *this* one, but I can't assume anything.
I'm not 100% certain this is an odbc-thing, frankly, but I am also not where else the problem can be addressed.
Database
1> select @@VERSION
2> GO
Microsoft SQL Server 2017 (RTM-CU9-GDR) (KB4293805) - 14.0.3035.2 (X64)
Jul 6 2018 18:24:36
Copyright (C) 2017 Microsoft Corporation
Developer Edition (64-bit) on Linux (Ubuntu 16.04.5 LTS)
Reproducible Example
library(DBI)
con<- dbConnect(odbc::odbc(),
driver='ODBC Driver 13 for SQL Server',
server='127.0.0.1,31433',
database='master',
uid='SA', pwd='Mysecretpassword1')
qry<-"create table test1 ( id UNIQUEIDENTIFIER DEFAULT NEWSEQUENTIALID() PRIMARY KEY NOT NULL , f_int INT , f_psx DATETIME, f_psx2 DATETIMEOFFSET )"data1<-data.frame(
f_int=1L,
f_psx= Sys.time(),
f_psx2= Sys.time(),
stringsAsFactors=FALSE
)
withr::with_options(list(digits.secs=6), print(data1$f_psx))
# [1] "2018-08-16 23:14:18.559138 UTC" # currently -7, so 23:14:18 UTC
attr(data1$f_psx, "tz") # to show on TZ assigned yet# NULL
dbExecute(con, qry)
# [1] 0
dbWriteTable(con, 'test1', data1, create=FALSE, append=TRUE)
str( dbGetQuery(con, "select * from test1") )
# 'data.frame': 1 obs. of 4 variables:# $ id : chr "7DDA423E-F36B-1410-8A8F-007D77BBB095"# $ f_int : int 1# $ f_psx : POSIXct, format: "2018-08-16 23:14:18"# $ f_psx2: chr "2018-08-16 23:14:18 Pacific Standard Time"
Most of the $f_psx2 string is easily parsed into POSIXt, but the TZ is confounding me.
I would be happier with just the character representation from the server, frankly, since that contains a numeric offset and therefore much easier to parse.
For the record:
Sys.timezone()
# [1] "America/Los_Angeles"
This is what the database sees:
1>select f_int,f_psx,f_psx2 from test1
2> go
f_int f_psx f_psx2
----------- ----------------------- ---------------------------------------------12018-08-1623:14:18.0002018-08-1623:14:18.0000000-07:00
and similarly, Excel with Microsoft Query:
So the first column is just a DATETIME sans TZ info, which is unacceptable for my use (I could soap-box a long time about databasers who think it's okay to trust clients and programs to always insert times with the same TZ offset).
This doesn't change if R has a TZ attached to the data:
data1$f_int<-2L
( data1$f_psx<- .POSIXct(data1$f_psx, "US/Pacific") )
# [1] "2018-08-16 16:14:18 PDT"
dbWriteTable(con, 'test1', data1, create=FALSE, append=TRUE)
str( dbGetQuery(con, "select * from test1 where f_int = 2") )
# 'data.frame': 1 obs. of 4 variables:# $ id : chr "80DA423E-F36B-1410-8A8F-007D77BBB095"# $ f_int : int 2# $ f_psx : POSIXct, format: "2018-08-16 23:14:18"# $ f_psx2: chr "2018-08-16 23:14:18 Pacific Standard Time"data1$f_int<-3L
( data1$f_psx<- .POSIXct(data1$f_psx, "UTC") )
# [1] "2018-08-16 23:14:18 UTC"
dbWriteTable(con, 'test1', data1, create=FALSE, append=TRUE)
str( dbGetQuery(con, "select * from test1 where f_int = 3") )
# 'data.frame': 1 obs. of 4 variables:# $ id : chr "87DA423E-F36B-1410-8A8F-007D77BBB095"# $ f_int : int 3# $ f_psx : POSIXct, format: "2018-08-16 23:14:18"# $ f_psx2: chr "2018-08-16 23:14:18 Pacific Standard Time"
- fix format of returned object of type `DATETIMEOFFSET` (-155) from
`"2018-09-12 22:38:56 Pacific Standard Time"` to
`"2018-09-13 05:41:20.4607764 +00:00"`
- closesr-dbi#207, "datetimeoffset unsupported" (in modern SQL Server ODBC
drivers)
- fix format of returned object of type `DATETIMEOFFSET` (-155) from
`"2018-09-12 22:38:56 Pacific Standard Time"` to
`"2018-09-13 05:41:20.4607764 +00:00"`
- closes#207, "datetimeoffset unsupported" (in modern SQL Server ODBC
drivers)
Issue Description and Expected Result
The SQL Server
DATETIMEOFFSET
field is not recognized and/or formatted correctly. Instead of a "usable" timezone, it's including a rather-verbose version:"2018-08-16 23:14:18 Pacific Standard Time"
. I can't find it anywhere in the source forodbc
orDBI
, though I do find it in the R sourceextra/tzone/registryTZ.c
. I know *this* one, but I can't assume anything.I'm not 100% certain this is an
odbc
-thing, frankly, but I am also not where else the problem can be addressed.Database
Reproducible Example
Most of the
$f_psx2
string is easily parsed intoPOSIXt
, but the TZ is confounding me.I would be happier with just the character representation from the server, frankly, since that contains a numeric offset and therefore much easier to parse.
For the record:
Sys.timezone() # [1] "America/Los_Angeles"
This is what the database sees:
and similarly, Excel with Microsoft Query:
So the first column is just a
DATETIME
sans TZ info, which is unacceptable for my use (I could soap-box a long time about databasers who think it's okay to trust clients and programs to always insert times with the same TZ offset).This doesn't change if R has a TZ attached to the data:
Session Info
The text was updated successfully, but these errors were encountered: