tbl <- "featured_playlists"
schema <- "dev.spotify"
comment <- 'Webscrape of Spotify Featured Playlists by datetime and country'

if ("timestamp" %in% names(DT.featured_playlists))
  setnames(DT.featured_playlists, "timestamp", "datetime_featured_UTC")

ingestIntoSQL(DT.featured_playlists, schema=schema, comment=comment, diststyle=NULL, boolean_type="INT", datetime_type="TIMESTAMP_NTZ", upperColnames=FALSE, quoteColnames=FALSE, drop=TRUE, maxBytes_for_insertStatement=as.integer(1e5 / 3))

qry_create_insert <- makeSQLtable(DT.featured_playlists, table.name=tbl, schema=schema, comment=comment, diststyle=NULL, boolean_type="INT", datetime_type="TIMESTAMP_NTZ", upperColnames=FALSE, quoteColnames=FALSE)

## Chop up the INSERT query into multiple smaller queries
queries_insert <- chopQryInsert(qry_create_insert$QRY.insert, max=1e5)


## RESET:  Dropping table
# sfQry("DROP TABLE dev.spotify.featured_playlists")

existing_tables <- sfShowTables(schema=schema, verbose=FALSE)
if (!any(grepl(tbl, existing_tables$name, ignore.case=TRUE))) {
  verboseMsg(verbose, "Creating table   '", schemaPaste(schema, tbl), "'", sep="")

  ## CREATE TABLE
  sfQry(qry=qry_create_insert$QRY.create)

  ## CONFIRM EXISTS
  existing_tables <- sfShowTables(schema=schema, verbose=FALSE)
  if (any(grepl(tbl, existing_tables$name, ignore.case=TRUE))) {
    verboseMsg(verbose, "Confirmed that the table was properly created")
  } else {
    warning("table '", schemaPaste(schema, tbl), "' was not properly created", call.=FALSE)
  }
}

if (FALSE) {
  ret <- queries_insert %>% sapply(sfQry, verbose=TRUE)
}

## ALTERNATE
if (FALSE) {
  sqlUpdate(sfcon, dat=DT.featured_playlists[1:10]
    , tablename = schemaPaste(schema, tbl)
    , index = NULL
    , verbose = FALSE
    , test = TRUE
    , nastring = NULL
    , fast = TRUE)
}
