# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
#' @include PrestoConnection.R
NULL
#' Compose query to create a simple table using a statement
#'
#' @param con A database connection.
#' @param name The table name, passed on to [dbQuoteIdentifier()]. Options are:
#' - a character string with the unquoted DBMS table name,
#' e.g. `"table_name"`,
#' - a call to [Id()] with components to the fully qualified table name,
#' e.g. `Id(schema = "my_schema", table = "table_name")`
#' - a call to [SQL()] with the quoted and fully qualified table name
#' given verbatim, e.g. `SQL('"my_schema"."table_name"')`
#' @param sql a character string containing SQL statement.
#' @param with An optional WITH clause for the CREATE TABLE statement.
#' @param ... Other arguments used by individual methods.
#' @export
#' @md
setGeneric("sqlCreateTableAs",
def = function(con, name, sql, with = NULL, ...) {
standardGeneric("sqlCreateTableAs")
}
)
#' @rdname PrestoConnection-class
#' @usage NULL
.sqlCreateTableAs <- function(con, name, sql, with = NULL, ...) {
name <- DBI::dbQuoteIdentifier(con, name)
DBI::SQL(paste0(
"CREATE TABLE ", name, "\n",
if (!is.null(with)) paste0(with, "\n"),
"AS\n",
sql
))
}
#' @rdname PrestoConnection-class
#' @export
setMethod("sqlCreateTableAs", signature("PrestoConnection"), .sqlCreateTableAs)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.