File: timeTypeComparison.r

package info (click to toggle)
r-cran-rpostgresql 0.6-2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 940 kB
  • sloc: ansic: 3,091; sh: 2,863; makefile: 7
file content (39 lines) | stat: -rwxr-xr-x 1,142 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/r

suppressMessages({
    library(RODBC)
    library(RPostgreSQL)
})

testTimeData <- function(tt = "date") {

    createTempTable(tt)

    channel <- odbcConnect("beancounter")
    odbcres <- sqlQuery(channel, "select * from timetest")
    close(channel)

    con <- dbConnect( dbDriver("PostgreSQL"), dbname="beancounter")
    pgres <- dbGetQuery(con, "select * from timetest")
    dbDisconnect(con)

    removeTempTable()

    cat("\nFor type='", tt, "'\nODBC returns ", format(odbcres[1,1]), " class ", class(odbcres[1,1]),
        "\nRPostgreSQL returns ", format(pgres[1,1]), " class ", class(pgres[1,1]), "\n", sep="")
}

createTempTable <- function(tt) {
    system(paste("psql beancounter -c \"create table timetest ( d1", tt, ")\" >/dev/null"))
    system("psql beancounter -c \"insert into timetest values( \'now\' )\" >/dev/null")
}

removeTempTable <- function() {
    system("psql beancounter -c \"drop table timetest\" >/dev/null")
}

testTimeData("date")
testTimeData("timestamp with time zone")
testTimeData("timestamp without time zone")
testTimeData("time with time zone")
testTimeData("time without time zone")