GithubHelp home page GithubHelp logo

wrightcameron / sql-handleduplicate-example Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 9 KB

Postgres database example project for demonstrating how duplicate data can appear and how to resolve the issue.

Makefile 2.04% PLpgSQL 90.50% Shell 7.46%
postgresql sql

sql-handleduplicate-example's Introduction

SQL Duplication Handling Example

Requirements

  • Docker (For postgres image)
  • psql CLI tool (Accessing postgres database)

Setup

A Makefile has been created to handle setting up everything automatically, though you can still follow the instructions below to do it manually.

To build the project with the make file, run the command make from the repo. To clean run command, make clean

Database Creation

Creating a postgres database can be done with docker with the following command.

docker run --rm -p 5432:5432 --name postgres -e POSTGRES_PASSWORD=pass -d postgres

This setups an empty postgres database, that when stopped will remove all data. This example doesn't require data to persist so we can add it every time.

Creating Schema

The schema is defined in the file ./setup/schema.sql To add schema run command, psql -U postgres -h localhost -f ./setup/schema.sql.

Adding Data

The data to add is in file ./setup/data.sql. To add this as well run command, psql -U postgres -h localhost -f ./setup/data.sql.

Viewing Data

Accessing Database with psql

psql is a command line tool for accessing postgres databases. On Debian it can be installed with command sudo apt install postgresql-client

To access the postgres database use psql -U postgres -h localhost.

Some helpful commands with postgres are.

  • \q - quit
  • \l - list databases
  • \c - switch database
  • \du - list users, more info with \du+
  • \dn - list schemas
  • \dt - list tables
  • \d \d+ <table name> - describe table name

More commands can be found with man psql or searching online, but the ones above are the most common I use.

Psql is a CLI tool for accessing

Adminer

An Adminer image is added to the docker-compose file. Adminer provides a website shell for viewing, adding, or modifying the database data and schema. It can be accessed by going to localhost:8080 in an Internet Browser. Note that the server hostname is postgres as defined in docker-compose. Username and database are also postgres.

Problem

The satellite SQL database tracks thousands and thousands of satellites in orbit. This database is used by hundreds of clients to keep track of public records saying who has what in the sky. There is an issue though, some of the records are showing duplicates. These duplicates need to be removed, but a single entry needs to remain and which of the duplicates should be the one to remain?

Solution

View solution.md for walk through.

Resources

sql-handleduplicate-example's People

Contributors

wrightcameron 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.