Uploads a data frame, a csv file, or file on S3 to Redshift based on the first argument.
A default database can be set using options(civis.default_db = "my_database")
.
If there is only one database available,
this database will automatically be used as the default.
write_civis(x, ...)# S3 method for data.frame
write_civis(
x,
tablename,
database = NULL,
if_exists = "fail",
distkey = NULL,
sortkey1 = NULL,
sortkey2 = NULL,
max_errors = NULL,
verbose = FALSE,
hidden = TRUE,
diststyle = NULL,
header = TRUE,
credential_id = NULL,
import_args = NULL,
...
)
# S3 method for character
write_civis(
x,
tablename,
database = NULL,
if_exists = "fail",
distkey = NULL,
sortkey1 = NULL,
sortkey2 = NULL,
max_errors = NULL,
verbose = FALSE,
hidden = TRUE,
diststyle = NULL,
header = TRUE,
credential_id = NULL,
import_args = NULL,
...
)
# S3 method for numeric
write_civis(
x,
tablename,
database = NULL,
if_exists = "fail",
distkey = NULL,
sortkey1 = NULL,
sortkey2 = NULL,
max_errors = NULL,
verbose = FALSE,
delimiter = ",",
hidden = TRUE,
diststyle = NULL,
header = TRUE,
credential_id = NULL,
import_args = NULL,
...
)
data frame, file path of a csv, or the id of a csv file on S3 to upload to platform.
arguments passed to write.csv
.
string, Name of table and schema "schema.tablename"
.
string, Name of database where data frame is to be uploaded. If no database is specified,
uses options(civis.default_db)
.
string, optional, String indicating action to take if table already exists. Must be either "fail", "drop", "truncate" or "append". Defaults to "fail".
string, optional, Column name designating the distkey.
string, optional, Column name designating the first sortkey.
string, optional, Column name designating the second (compound) sortkey.
int, optional, Maximum number of rows with errors to remove before failing.
bool, Set to TRUE to print intermediate progress indicators.
bool, if TRUE
(default), this job will not appear in the Civis UI.
string optional. The diststyle to use for the table. One of "even", "all", or "key".
bool, if TRUE
(default) the first row is a header.
integer, the id of the credential to be used when performing
the database import. If NULL
(default), the default credential of the
current user will be used.
list of additional arguments for imports_post_files
.
string, optional. Which delimiter to use. One of
','
, '\t'
or '|'
.
data.frame
: Upload a data frame to Civis Platform (Redshift).
character
: Upload a csv to Civis Platform (Redshift).
numeric
: Upload a csv file from the files endpoint to Civis Platform (Redshift)
refresh_table
to update table meta-data.
Other io:
download_civis()
,
query_civis_file()
,
query_civis()
,
read_civis()
,
write_civis_file()
if (FALSE) {
df <- read.csv(local_file)
# Create new table, fail if already exists
write_civis(df, "schema.my_table", "my_database")
# Create new table, append if already exists
write_civis(df, "schema.my_table", "my_database", if_exists="append")
# Create new table with additional options
write_civis(df, "schema.my_table", "my_database",
distkey="id",
sortkey1="added_date",
credential_id = 1,
header = FALSE)
# Create new table directly from a saved csv
write_civis("my/file/path.csv", "schema.my_table", "my_database")
# Create new table from a file_id
id <- write_civis_file("my/file/path.csv", name = "path.csv")
write_civis(id, "schema.my_table", "my_database")
}
Run the code above in your browser using DataLab