RSQLite odbc dbDataType date format different
Why is the representation of the POSIXct date format different on the same SQLite DB depending on the used driver?
The ODBC driver version 0.9996 for Windows is from:
http://www.ch-werner.de/sqliteodbc/
library(tidyverse)
library(lubridate)
library(RSQLite)
library(odbc)
df <- tribble(~idx, ~date, 1, now())
df
# A tibble: 1 x 2
idx date
<dbl> <dttm>
1 1 2018-11-14 13:32:12
conFile <- dbConnect(RSQLite::SQLite(), "test.db")
# ODBC source test_db to be defined on the same file test.db with ODBC diver for Windows please
conOdbc <- dbConnect(odbc::odbc(), "test_db")
dbWriteTable(conFile, "dfFile", df)
dbWriteTable(conOdbc, "dfOdbc", df)
dfFile <- tbl(conFile, "dfFile")
dfOdbc <- tbl(conOdbc, "dfOdbc")
dfFile %>% collect()
# Source: table<dfFile> [?? x 2]
# Database: sqlite 3.22.0 [C:UserszfgbeDesktopRtest.db]
idx date
<dbl> <dbl>
1 1 1542198732.
dfOdbc %>% collect()
# Source: table<dfOdbc> [?? x 2]
# Database: SQLite
# 3.22.0[@C:UserszfgbeDesktopRdbtest.db/C:UserszfgbeDesktopRdbtest.db]
idx date
<dbl> <dbl>
1 1 2018
td <- now()
dbDataType(conFile, td)
[1] "REAL"
dbDataType(conOdbc, td)
[1] "NUMERIC"
r sqlite odbc rsqlite
add a comment |
Why is the representation of the POSIXct date format different on the same SQLite DB depending on the used driver?
The ODBC driver version 0.9996 for Windows is from:
http://www.ch-werner.de/sqliteodbc/
library(tidyverse)
library(lubridate)
library(RSQLite)
library(odbc)
df <- tribble(~idx, ~date, 1, now())
df
# A tibble: 1 x 2
idx date
<dbl> <dttm>
1 1 2018-11-14 13:32:12
conFile <- dbConnect(RSQLite::SQLite(), "test.db")
# ODBC source test_db to be defined on the same file test.db with ODBC diver for Windows please
conOdbc <- dbConnect(odbc::odbc(), "test_db")
dbWriteTable(conFile, "dfFile", df)
dbWriteTable(conOdbc, "dfOdbc", df)
dfFile <- tbl(conFile, "dfFile")
dfOdbc <- tbl(conOdbc, "dfOdbc")
dfFile %>% collect()
# Source: table<dfFile> [?? x 2]
# Database: sqlite 3.22.0 [C:UserszfgbeDesktopRtest.db]
idx date
<dbl> <dbl>
1 1 1542198732.
dfOdbc %>% collect()
# Source: table<dfOdbc> [?? x 2]
# Database: SQLite
# 3.22.0[@C:UserszfgbeDesktopRdbtest.db/C:UserszfgbeDesktopRdbtest.db]
idx date
<dbl> <dbl>
1 1 2018
td <- now()
dbDataType(conFile, td)
[1] "REAL"
dbDataType(conOdbc, td)
[1] "NUMERIC"
r sqlite odbc rsqlite
The two drivers serialize time values in different ways. Remember, there is no such thing as a date or time type in sqlite. The file one looks like it uses Unix time, the odbc one... Not sure unless the output of that table was truncated by the display code. sqlite.org/datatype3.html is essential reading about sqlite types and column affinities, though.
– Shawn
Nov 14 '18 at 13:25
Thx Shawn, I also found this link about the ODBC driver ch-werner.de/sqliteodbc/html/index.html I run into a problem by this different representation of the date format. What is the best way to represent dates in SQLite, as character?
– Guido Berning
Nov 14 '18 at 13:41
It seams that the Windows ODBC driver converts to single quoted string for the date format. By changing the configuration inside the Windows ODBC DNS for the test.db to use 'Julian Day conv.' this behaviour changes. But the values still differ. There for I send a mail to the developer of the driver it it's possible to add another configuration parameter to do a conversion from POSIXct representation as type real. (see value 1542198732 in the question).
– Guido Berning
Nov 14 '18 at 14:46
add a comment |
Why is the representation of the POSIXct date format different on the same SQLite DB depending on the used driver?
The ODBC driver version 0.9996 for Windows is from:
http://www.ch-werner.de/sqliteodbc/
library(tidyverse)
library(lubridate)
library(RSQLite)
library(odbc)
df <- tribble(~idx, ~date, 1, now())
df
# A tibble: 1 x 2
idx date
<dbl> <dttm>
1 1 2018-11-14 13:32:12
conFile <- dbConnect(RSQLite::SQLite(), "test.db")
# ODBC source test_db to be defined on the same file test.db with ODBC diver for Windows please
conOdbc <- dbConnect(odbc::odbc(), "test_db")
dbWriteTable(conFile, "dfFile", df)
dbWriteTable(conOdbc, "dfOdbc", df)
dfFile <- tbl(conFile, "dfFile")
dfOdbc <- tbl(conOdbc, "dfOdbc")
dfFile %>% collect()
# Source: table<dfFile> [?? x 2]
# Database: sqlite 3.22.0 [C:UserszfgbeDesktopRtest.db]
idx date
<dbl> <dbl>
1 1 1542198732.
dfOdbc %>% collect()
# Source: table<dfOdbc> [?? x 2]
# Database: SQLite
# 3.22.0[@C:UserszfgbeDesktopRdbtest.db/C:UserszfgbeDesktopRdbtest.db]
idx date
<dbl> <dbl>
1 1 2018
td <- now()
dbDataType(conFile, td)
[1] "REAL"
dbDataType(conOdbc, td)
[1] "NUMERIC"
r sqlite odbc rsqlite
Why is the representation of the POSIXct date format different on the same SQLite DB depending on the used driver?
The ODBC driver version 0.9996 for Windows is from:
http://www.ch-werner.de/sqliteodbc/
library(tidyverse)
library(lubridate)
library(RSQLite)
library(odbc)
df <- tribble(~idx, ~date, 1, now())
df
# A tibble: 1 x 2
idx date
<dbl> <dttm>
1 1 2018-11-14 13:32:12
conFile <- dbConnect(RSQLite::SQLite(), "test.db")
# ODBC source test_db to be defined on the same file test.db with ODBC diver for Windows please
conOdbc <- dbConnect(odbc::odbc(), "test_db")
dbWriteTable(conFile, "dfFile", df)
dbWriteTable(conOdbc, "dfOdbc", df)
dfFile <- tbl(conFile, "dfFile")
dfOdbc <- tbl(conOdbc, "dfOdbc")
dfFile %>% collect()
# Source: table<dfFile> [?? x 2]
# Database: sqlite 3.22.0 [C:UserszfgbeDesktopRtest.db]
idx date
<dbl> <dbl>
1 1 1542198732.
dfOdbc %>% collect()
# Source: table<dfOdbc> [?? x 2]
# Database: SQLite
# 3.22.0[@C:UserszfgbeDesktopRdbtest.db/C:UserszfgbeDesktopRdbtest.db]
idx date
<dbl> <dbl>
1 1 2018
td <- now()
dbDataType(conFile, td)
[1] "REAL"
dbDataType(conOdbc, td)
[1] "NUMERIC"
r sqlite odbc rsqlite
r sqlite odbc rsqlite
edited Nov 14 '18 at 13:11
Guido Berning
asked Nov 14 '18 at 12:52
Guido BerningGuido Berning
296
296
The two drivers serialize time values in different ways. Remember, there is no such thing as a date or time type in sqlite. The file one looks like it uses Unix time, the odbc one... Not sure unless the output of that table was truncated by the display code. sqlite.org/datatype3.html is essential reading about sqlite types and column affinities, though.
– Shawn
Nov 14 '18 at 13:25
Thx Shawn, I also found this link about the ODBC driver ch-werner.de/sqliteodbc/html/index.html I run into a problem by this different representation of the date format. What is the best way to represent dates in SQLite, as character?
– Guido Berning
Nov 14 '18 at 13:41
It seams that the Windows ODBC driver converts to single quoted string for the date format. By changing the configuration inside the Windows ODBC DNS for the test.db to use 'Julian Day conv.' this behaviour changes. But the values still differ. There for I send a mail to the developer of the driver it it's possible to add another configuration parameter to do a conversion from POSIXct representation as type real. (see value 1542198732 in the question).
– Guido Berning
Nov 14 '18 at 14:46
add a comment |
The two drivers serialize time values in different ways. Remember, there is no such thing as a date or time type in sqlite. The file one looks like it uses Unix time, the odbc one... Not sure unless the output of that table was truncated by the display code. sqlite.org/datatype3.html is essential reading about sqlite types and column affinities, though.
– Shawn
Nov 14 '18 at 13:25
Thx Shawn, I also found this link about the ODBC driver ch-werner.de/sqliteodbc/html/index.html I run into a problem by this different representation of the date format. What is the best way to represent dates in SQLite, as character?
– Guido Berning
Nov 14 '18 at 13:41
It seams that the Windows ODBC driver converts to single quoted string for the date format. By changing the configuration inside the Windows ODBC DNS for the test.db to use 'Julian Day conv.' this behaviour changes. But the values still differ. There for I send a mail to the developer of the driver it it's possible to add another configuration parameter to do a conversion from POSIXct representation as type real. (see value 1542198732 in the question).
– Guido Berning
Nov 14 '18 at 14:46
The two drivers serialize time values in different ways. Remember, there is no such thing as a date or time type in sqlite. The file one looks like it uses Unix time, the odbc one... Not sure unless the output of that table was truncated by the display code. sqlite.org/datatype3.html is essential reading about sqlite types and column affinities, though.
– Shawn
Nov 14 '18 at 13:25
The two drivers serialize time values in different ways. Remember, there is no such thing as a date or time type in sqlite. The file one looks like it uses Unix time, the odbc one... Not sure unless the output of that table was truncated by the display code. sqlite.org/datatype3.html is essential reading about sqlite types and column affinities, though.
– Shawn
Nov 14 '18 at 13:25
Thx Shawn, I also found this link about the ODBC driver ch-werner.de/sqliteodbc/html/index.html I run into a problem by this different representation of the date format. What is the best way to represent dates in SQLite, as character?
– Guido Berning
Nov 14 '18 at 13:41
Thx Shawn, I also found this link about the ODBC driver ch-werner.de/sqliteodbc/html/index.html I run into a problem by this different representation of the date format. What is the best way to represent dates in SQLite, as character?
– Guido Berning
Nov 14 '18 at 13:41
It seams that the Windows ODBC driver converts to single quoted string for the date format. By changing the configuration inside the Windows ODBC DNS for the test.db to use 'Julian Day conv.' this behaviour changes. But the values still differ. There for I send a mail to the developer of the driver it it's possible to add another configuration parameter to do a conversion from POSIXct representation as type real. (see value 1542198732 in the question).
– Guido Berning
Nov 14 '18 at 14:46
It seams that the Windows ODBC driver converts to single quoted string for the date format. By changing the configuration inside the Windows ODBC DNS for the test.db to use 'Julian Day conv.' this behaviour changes. But the values still differ. There for I send a mail to the developer of the driver it it's possible to add another configuration parameter to do a conversion from POSIXct representation as type real. (see value 1542198732 in the question).
– Guido Berning
Nov 14 '18 at 14:46
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300706%2frsqlite-odbc-dbdatatype-date-format-different%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300706%2frsqlite-odbc-dbdatatype-date-format-different%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The two drivers serialize time values in different ways. Remember, there is no such thing as a date or time type in sqlite. The file one looks like it uses Unix time, the odbc one... Not sure unless the output of that table was truncated by the display code. sqlite.org/datatype3.html is essential reading about sqlite types and column affinities, though.
– Shawn
Nov 14 '18 at 13:25
Thx Shawn, I also found this link about the ODBC driver ch-werner.de/sqliteodbc/html/index.html I run into a problem by this different representation of the date format. What is the best way to represent dates in SQLite, as character?
– Guido Berning
Nov 14 '18 at 13:41
It seams that the Windows ODBC driver converts to single quoted string for the date format. By changing the configuration inside the Windows ODBC DNS for the test.db to use 'Julian Day conv.' this behaviour changes. But the values still differ. There for I send a mail to the developer of the driver it it's possible to add another configuration parameter to do a conversion from POSIXct representation as type real. (see value 1542198732 in the question).
– Guido Berning
Nov 14 '18 at 14:46