
This is the `getReleaseDates()` function from SpotifyAdds. 
This might be helpful for generalizing. 


     NOTE:  DO NOT CONFUSE THIS WITH THE _ACTUAL_ getReleaseDates


getReleaseDates
function(values, id.col="releaseId", id.col.AS=id.col
                        , numericValues=FALSE, sep="__", origin="1970-01-01"
                        , genre=TRUE
                        , dontExecute.justReturnQry=FALSE, verbose=TRUE, verbose.max.width=98L+(200*dontExecute.justReturnQry)
                        , minimal=is.null(values)) {

  force (minimal)

  if (length(genre) && !is.logical(genre))
    stop ("genre should be a logical value")
  if (!isTRUE(genre))  # treat NULL / NA as FALSE
    genre <- FALSE

  quotes <- ifelse(numericValues, "", "\'")

  ## DROP NA's
  if (!is.null(values))
    values <- unique(removeNA(values))

  cols.rel <- c(  paste(id.col, "AS", id.col.AS)
                , "releaseName AS 'release'", "releaseDate"
                , "artistId AS artistId"
                , "mkt_priority", "product_type_id"
                )

  ## Some additional columns to include
  if (!minimal)
    cols.rel <- c(cols.rel, "vendor_catalog_number", "imprint"
                  , "sale_start_date", "original_release_date"
                  , "deletions", "manufacturer_upc", "version"
                  , "subaccountId", "display_upc", "vendor_release_identifier"
                  , "date_added AS", "last_updated AS", "date_created AS")


  cols.art   <- c("artistName AS artist", "last_updated AS", "date_created AS")
  cols.label <- c("labelName  AS label", "labelId",  "priority AS label_priority")
  cols.genre <- c("genreName  AS genre")

  cols.rel   <- makeProperColName("R", cols.rel,   AS.suffix="rel",   verbose=FALSE, sep=sep)
  cols.art   <- makeProperColName("A", cols.art,   AS.suffix="art",   verbose=FALSE, sep=sep)
  cols.label <- makeProperColName("L", cols.label, AS.suffix="label", verbose=FALSE, sep=sep)
  cols.genre <- makeProperColName("G", cols.genre, AS.suffix="genre", verbose=FALSE, sep=sep)
  
  ## IF adding columns from new tables, 
  ##    (a) append `select.what`  and (ba) append the table name in the joins

  select.what <- c(cols.rel, cols.art, cols.label)
  if (genre)
     select.what <- c(select.what, cols.genre)

  if (minimal) {
    ## Drop meta-data dates
    select.what <- select.what[!grepl("created|updated|added", select.what)]
    ## Drop any foreign keys
    select.what <- select.what[!(grepl("Id$", select.what) & !grepl(paste0("AS ", id.col.AS, "$"), select.what))]
  }

  ## ------------  THE QUERY  ------------ #
  Q <- paste( "SELECT ", paste(select.what, collapse=", ")
                       , ", C1.country_code AS artist_country"
                       , ", C2.country_code AS label_country"

            , "FROM   dim_release R"
            , "LEFT JOIN dim_artist A     ON    R.artistId   = A.artistId"
            , "LEFT JOIN dim_label L      ON    R.labelId    = L.labelId"
            , "LEFT JOIN dim_country C1   ON    C1.countryId = A.countryId"
            , "LEFT JOIN dim_country C2   ON    C2.countryId = L.countryId"
            , if (genre) 
                "LEFT JOIN dim_genre G      ON    R.genreId    = G.genreId"

            , if (!is.null(values))
                paste("WHERE", paste0("R.", id.col), "in", pasteQ(values, q=quotes))
            # , "ORDER BY artistName"
            ,  sep=" "
            )
  ## ------------  THE QUERY  ------------ #

  ## Optionally, just output the Query
  if (dontExecute.justReturnQry) {
    if (verbose)
      cat("\n", verboseQry(Q, max.lines=35L, max.width=verbose.max.width, indentOr=TRUE), "\n", sep="")
    return(invisible(Q))
  }

  ## Try to detach RPostgreSQL
  ## ------------------------------ ##
  try(dbDisconnect(con), silent=TRUE)
  try(detach(package:RPostgreSQL), silent=TRUE)
  require(RMySQL)
  ## ------------------------------ ##

  DT.releaseDates <- runQry(qry=Q, connex=getDB(drv.str="MySQL"), verbose.shortCircuit=FALSE)

  ## WRAPPING IN TRY SO AS TO NOT KILL THE WHOLE RUN IF FAILED
  succesfulRun <- FALSE
  try({
    cleanReleaseDatesDT_(DT.releaseDates, minimal=minimal)
    succesfulRun <- TRUE
  })

  if (!succesfulRun) 
    warning("Qry was successful but this function failed at the point of cleaning the column types.\nPlease manually check")

  return(DT.releaseDates)
}