Giter Club home page Giter Club logo

postgresql_tutorial1's Introduction

postgresql_tutorial1

Basic introduction to PostgreSQL

Introduction

This repository provides an intro to PostgreSQL (postgres) database (db).


Install Postgres

Database connection parameters

The connection details are as follows:

  • IP: IP
  • Port: 5432
  • Data base: georodco_covid19
  • user name: username
  • password: password

Using the above parameters you can connect to the db using your prefered choice of statitical program (R, Stata, Excel, etc.)

Postgres and R

R is an open-source computational and statistical program. You can download it from here: R-project

  • Using R with data from a Postgres db

      # Install libraries (only once)
      install.packages("DBI") # Generic database connector
      #install.packages("RPostgreSQL")
      #install.packages("rpostgis") # optional
    
      # Load library
      library(DBI)
      library(RPostgreSQL)
      library(RPostgis) # optional
    
    
      # create conection to the db
      con <- DBI::dbConnect(drv = "PostgreSQL", user='user', password='password', host='IP', port=5432, dbname='georodco_covid19')
    
      # ask db for table ecu_covid19
      res <- dbSendQuery(con, "SELECT * FROM ecu_covid19")
      cv19 <- dbFetch(res)
    
      # check number of rows and columns (25x15)
      dim(cv19)
    
      # check out first (6) rows in the table
      head(cv19)
    
      # Working with spatial data found in Postgres
      #Method 1: use package sf
      library(sf)
      prov <- st_read(con, layer="provinces")
      library(ggplot2)
      ggplot(prov) +  geom_sf() + theme_bw()
    
      # delete connection object
      dbClearResult(res)
    
      # disconnect from the db
      dbDisconnect(con)
    

Postgres for data management

Relational dbs are flexible, extensible, and scalable. They are very useful for managing data in colloborative projects.

postgresql_tutorial1's People

Contributors

georod avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.