The first step is to reference the table in the database using tbl(). DBI::dbGetQuery(con, "select * from trial_db") # Warning: Closing open result set, pending rows # x y Let us check if the new row of data has been inserted into the trial_db table by querying data from the same table. In the next example, we insert another row of data into the trial_db table in the database using dbSendStatement(). DBI::dbGetQuery(con, "select * from trial_db") # x y In the below example, we insert a new row of data into the trial-db table in the database using `dbExecute(). We can insert new rows into existing tables using: # 10 20 social tablet false 2 1 28 Namibia false # 9 19 social tablet false 7 10 290 Colombia true # 8 18 google tablet true 7 1 406 China false # 7 17 bing tablet false 5 16 368 Peru true # 6 16 bing laptop true 1 1 995 United States false # 5 15 yahoo mobile false 7 1 19 France false # 4 14 yahoo tablet false 5 8 80 Philippines false # 3 13 direct mobile false 9 14 406 Ireland true # 2 12 direct tablet false 6 12 132 Estonia false # 1 11 direct laptop true 9 1 738 Jamaica false # 10 10 google mobile true 6 1 208 Czech Republic false # 9 9 bing mobile false 3 19 209 Netherlands false # 8 8 direct mobile true 10 1 908 Indonesia false # 7 7 yahoo mobile true 10 1 75 Bangladesh false ![]() # 6 6 yahoo laptop false 5 5 135 South Africa false # 5 5 yahoo mobile true 9 1 955 Poland false ![]() # 4 4 bing tablet false 3 18 468 China true # 3 3 direct laptop true 0 1 996 Brazil false # 2 2 yahoo tablet true 9 1 459 Yemen false # 1 1 google laptop true 10 1 693 Czech Republic false Read Data in Batches query <- DBI::dbSendQuery(con, 'select * from ecom')ĭBI::dbFetch(query, n = 10) # id referrer device bouncers n_visit n_pages duration country purchase Now that we know how to connect to a database and list the fields/columns, let us move on to the next section where we will learn how to query data from the tables present in the database.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |