test_that("fractional seconds can be roundtripped", {
  skip_if_not(TEST_RE2)

  con <- local_con()

  df <- data.frame(a = as.POSIXct(
    1.234567 + (1:100) * 1e-6,
    origin = structure(0, class = c("POSIXct", "POSIXt")),
    tz = "UTC"
  ))
  dbWriteTable(con, "df", df)
  df_out <- dbReadTable(con, "df")
  expect_equal(df_out, df)
})

test_that("fractional seconds can be extracted from TIME columns", {
  con <- local_con()

  data <- dbGetQuery(con, "SELECT TIME '01:02:03.45' AS a, INTERVAL '01:02:03.45' AS b")
  expect_equal(
    data$a,
    structure(3723.45, class = "difftime", units = "secs")
  )
  expect_equal(
    data$b,
    structure(3723.45, class = "difftime", units = "secs")
  )
})

test_that("TIME WITH TIME ZONE columns are returned as difftime (#1807)", {
  con <- local_con()

  data <- dbGetQuery(
    con,
    "SELECT
       TIMETZ '01:02:03.45+05:00' AS a,
       TIMETZ '01:02:03.45-05:00' AS b,
       TIMETZ '01:02:03.45+00:00' AS c,
       CAST(NULL AS TIMETZ) AS d"
  )
  expected <- structure(3723.45, class = "difftime", units = "secs")
  expect_equal(data$a, expected)
  expect_equal(data$b, expected)
  expect_equal(data$c, expected)
  expect_equal(data$d, structure(NA_real_, class = "difftime", units = "secs"))
})
