Creating a dataset in PostgreSQL from R
The PostgreSQL database server can be accessed from R through the RPostgreSQL
library. You can either create a new database, insert data into an existing database, or perform queries on the existing data tables. In this recipe, you will connect R with the PostgreSQL database server and create a table under the postgres
database, and insert data into the database.
Getting ready
To connect with the PostgreSQL database server from R, you are required to install the RPostgreSQL
library along with its dependencies. The following R code is to used install the necessary libraries to access the PostgreSQL database:
install.packages("RPostgreSQL", dependencies = TRUE)
In this recipe, the USAairlineData2016.csv
file has been used as a raw data source. You will insert the subset of this dataset into postgres
in the PostgreSQL database. The airlineDB
table will be created using R.
Note
Note that postgres
is the default database under the super user postgres
.