Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readme fixes #58

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,25 @@ As well as loading R dataframes into SQL Server databases, functions are also cu
It is recommend to ensure using the latest versions of [Rcpp](https://cran.r-project.org/web/packages/Rcpp/index.html), [odbc](https://cran.r-project.org/web/packages/odbc/index.html) and [DBI](https://cran.r-project.org/web/packages/DBI/index.html). If using Windows in a secure environment install these from source or a Windows binary compiled at the version of R you are using.

## Loading method used
When loading an R dataframe into SQL Server using `write_dataframe_to_db`, following steps are followed:
When loading an R dataframe into SQL Server using `write_dataframe_to_db`, the following steps are used:

1. The R dataframe is loaded into a staging table in the database in batches of n rows at a time.

2. a) If table of the specified name does NOT already exist in the database schema:
i) Create target table in the database.
ii) Insert all rows from staging table to target table.

3. b) If table of same name does already exist in the database schema:

If 'append_to_existing'=FALSE (this will result in an overwrite):
i) Drop the existing copy of the target table and create a new one from staging table definition.
ii) Insert all rows from staging table into target table.

If 'append_to_existing'=TRUE:
i) Check that staging table columns and existing target table columns are the same. If not, cancel loading and give a warning.
ii) If check passes, insert all rows from staging table into target table.
2. Create target table in the database and load from staging to target.

- If table of the specified name does NOT already exist in the database schema:
- Create target table in the database.
- Insert all rows from staging table to target table.

- If table of same name does already exist in the database schema:

- If argument `append_to_existing = FALSE` (this will result in an overwrite):
- Drop the existing copy of the target table and create a new one.
- Insert all rows from staging table into target table.

- If argument `append_to_existing = TRUE`:
- Check that staging table columns and existing target table columns are the same. If not, cancel loading and give a warning.
- If check passes, insert all rows from staging table into target table.

4. Delete the staging table.

Expand Down
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,34 @@ binary compiled at the version of R you are using.
## Loading method used

When loading an R dataframe into SQL Server using
`write_dataframe_to_db`, following steps are followed:
`write_dataframe_to_db`, the following steps are used:

1. The R dataframe is loaded into a staging table in the database in
batches of n rows at a time.

2. 1) If table of the specified name does NOT already exist in the
database schema:
1) Create target table in the database.
2) Insert all rows from staging table to target table.
2. Create target table in the database and load from staging to target.

3. 2) If table of same name does already exist in the database schema:
- If table of the specified name does NOT already exist in the
database schema:

If ‘append_to_existing’=FALSE (this will result in an overwrite):
- Create target table in the database.
- Insert all rows from staging table to target table.

1) Drop the existing copy of the target table and create a new one
from staging table definition.
2) Insert all rows from staging table into target table.
- If table of same name does already exist in the database schema:

If ‘append_to_existing’=TRUE:
- If argument `append_to_existing = FALSE` (this will result in an
overwrite):
- Drop the existing copy of the target table and create a new
one.
- Insert all rows from staging table into target table.
- If argument `append_to_existing = TRUE`:
- Check that staging table columns and existing target table
columns are the same. If not, cancel loading and give a
warning.
- If check passes, insert all rows from staging table into
target table.

1) Check that staging table columns and existing target table
columns are the same. If not, cancel loading and give a
warning.
2) If check passes, insert all rows from staging table into target
table.

4. Delete the staging table.
3. Delete the staging table.

## Example Usage

Expand Down
Loading