1 PostgreSQL: Ch 1-5 Learning to use it CSSE 533 Week 5, Spring, 2015.

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Advertisements

BA271 Week 6 Lecture Database Overview Dave Sullivan.
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
Winter 2002Judy Cushing8–1 Schedule Jan. 30 (Wed) u Modifications, Schemas, Views. Read Sections This Week (Feb 4ff) u Constraints Read Sections.
ISP 121 Week 1 Introduction to Databases. ISP 121, Winter Why a database and not a spreadsheet? You have too many separate files or too much data.
Living in a Digital World Discovering Computers 2010.
BUSINESS DRIVEN TECHNOLOGY
Access Lecture 1 Database Overview and Creating Tables Create an Employee Table.
Simple Web SQLite Manager/Form/Report
Confidential ODBC May 7, Features What is ODBC? Why Create an ODBC Driver for Rochade? How do we Expose Rochade as Relational Transformation.
Chapter 9 Database Management
Phil Brewster  One of the first steps – identify the proper data types  Decide how data (in columns) should be stored and used.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Module 1: Introduction to Microsoft SQL Server 7.0.
CSCI 6962: Server-side Design and Programming
Overview of SQL Server Alka Arora.
Classroom User Training June 29, 2005 Presented by:
Using XML in SQL Server 2005 NameTitleCompany. XML Overview Business Opportunity The majority of all data transmitted electronically between organizations.
1 Intro to Info Tech Database Management Systems Copyright 2003 by Janson Industries This presentation can be viewed on line at:
Discovering Computers Fundamentals, 2012 Edition Your Interactive Guide to the Digital World.
ASP.NET Programming with C# and SQL Server First Edition
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
MongoDB An introduction. What is MongoDB? The name Mongo is derived from Humongous To say that MongoDB can handle a humongous amount of data Document.
Views, Indexes and JDBC/JSP tutorial Professor: Dr. Shu-Ching Chen TA: Haiman Tian 1.
NoSQL continued CMSC 461 Michael Wilson. MongoDB  MongoDB is another NoSQL solution  Provides a bit more structure than a solution like Accumulo  Data.
INFO 344 Web Tools And Development CK Wang University of Washington Spring 2014.
1 Working with MS SQL Server Textbook Chapter 14.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with MSSQL Server Code:G0-C# Version: 1.0 Author: Pham Trung Hai CTD.
Management Information Systems MS Access MS Access is an application software that facilitates us to create Database Management Systems (DBMS)
Module 5 Planning for SQL Server® 2008 R2 Indexing.
Discovering Computers Fundamentals Fifth Edition Chapter 9 Database Management.
Objectives Overview Define the term, database, and explain how a database interacts with data and information Describe the qualities of valuable information.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Introduction to Relational Databases &
Data Management Console Synonym Editor
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
XP New Perspectives on Microsoft Access 2002 Tutorial 1 1 Microsoft Access 2002 Tutorial 1 – Introduction To Microsoft Access 2002.
MS Access 2007 Management Information Systems 1. Overview 2  What is MS Access?  Access Terminology  Access Window  Database Window  Create New Database.
VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Index and JDBC/JSP tutorial Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
A Brief Documentation.  Provides basic information about connection, server, and client.
Creating Databases Local storage. join & split Classwork: show 1 table application. Share designs for oscars application. Adaptive select. Homework: [Catch.
PostgreSQL ORDBMS. Server Hierarchy Managing Databases create database name; createdb name At the time of initialisation of Data Storage area by.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
BA271 Week 6 Lecture Dave Sullivan. Goal for today… Status Report – Review where we are … Status Report – Review where we are … Begin learning about Microsoft.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
SQL Server 2005: Extending the Type System with XML.
Some notes on NoSQL, in particular MongoDB Bettina Berendt (with thanks to Matthijs van Leeuwen for some of the slides) 8 December 2015.
POSTGRESQL 13 TH MARCH HISTORY DESIGNED BY MICHAEL STONEBRAKER ( ANDREW YU, JOLLY CHEN) AT UCLA (1999) COMMUNITY DEVELOPED 15 YEARS ACTIVE DEVELOPMENT.
Database Systems, 8 th Edition SQL Performance Tuning Evaluated from client perspective –Most current relational DBMSs perform automatic query optimization.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
11 Copyright © 2004, Oracle. All rights reserved. Managing XML Data in an Oracle 10g Database.
BTM 382 Database Management Chapter 8 Advanced SQL Chitu Okoli Associate Professor in Business Technology Management John Molson School of Business, Concordia.
Introduction to Database Programming with Python Gary Stewart
Lecture 1.21 SQL Introduction Steven Jones, Genome Sciences Centre.
CS320 Web and Internet Programming SQL and MySQL
Chapter Ten Managing a Database.
PostgreSQL Database and C++ Interface (and Midterm Topics)
Principles of report writing
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
Getting Started With Solr
Chapter 11 Managing Databases with SQL Server 2000
CS3220 Web and Internet Programming SQL and MySQL
XML? What’s this doing in my database? Adam Koehler
Presentation transcript:

1 PostgreSQL: Ch 1-5 Learning to use it CSSE 533 Week 5, Spring, 2015

2 Overview This week – Ch 1 – 5 – Learning to Use It This week – Ch 1 – 5 – Learning to Use It Your goals and starting points? Your goals and starting points? Ch 1 – The Basics Ch 1 – The Basics Database Drivers Database Drivers Ch 2 – Database Administration Ch 2 – Database Administration Extensions Extensions Ch 3 – psql Ch 3 – psql Ch 4 – Using pgAdmin Ch 4 – Using pgAdmin Ch 5 – Data Types Arrays, Range types, JSON Ref – Colorado State pdf – on Moodle Comparison of PostgreSQL with MS SQL Server Elephant says, Thursday topics are in red…

3 Your goals and starting points Experience with relational DBMS’s Experience with relational DBMS’s Project goals Project goals Areas of emphasis Areas of emphasis See suggested assignments with Ch 3 / 4 slides See suggested assignments with Ch 3 / 4 slides

4 Ch 1 – The Basics How to pronounce it – Bet you’ll hear different ways! How to pronounce it – Bet you’ll hear different ways! Where to get PostgreSQL Where to get PostgreSQL Admin tools Admin tools psql psql pgAdmin pgAdmin phpPgAdmin phpPgAdmin Adminer Adminer PostgreSQL database objects PostgreSQL database objects What’s new in the latest versions What’s new in the latest versions Database drivers, p 14  Where to get help Notable forks

5 Database Drivers – C++ C++ uses the libpqxx library. C++ uses the libpqxx library. See ql_c_cpp.htm See ql_c_cpp.htm ql_c_cpp.htm ql_c_cpp.htm Lots of examples like, on the next page, how to do an INSERT  Lots of examples like, on the next page, how to do an INSERT  Thursday topic

6 C++ Driver - Insert … /* Create SQL statement */ sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " \ "VALUES (1, 'Paul', 32, 'California', ); " \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " \ "VALUES (2, 'Allen', 25, 'Texas', ); " \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \ "VALUES (3, 'Teddy', 23, 'Norway', );" \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \ "VALUES (4, 'Mark', 25, 'Rich-Mond ', );"; /* Create a transactional object. */ work W(C); /* Execute SQL query */ W.exec( sql ); W.commit(); Thursday topic

7 Database drivers - Python Library – currently between psychopg and psycopg2. Library – currently between psychopg and psycopg2. See See Example – see next page  Example – see next page  Thursday topic

8 Python driver – read as array # If we are accessing the rows via column name instead of position we # need to add the arguments to conn.cursor. cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor) try: cur.execute("""SELECT * from bar""") except: print "I can't SELECT from bar" # # Note that below we are accessing the row via the column name. rows = cur.fetchall() for row in rows: print " ", row['notes'][1] Thursday topic

9 Drivers - Java As if! As if! See the Colorado State pdf on Moodle, starting on slide 28! See the Colorado State pdf on Moodle, starting on slide 28! Uses JDBC Uses JDBC But – they recommend Apache DBCP for “real world applications.” But – they recommend Apache DBCP for “real world applications.” Thursday topic

10 Ch 2 – Database Administration Configuration Files Configuration Files postgresql.conf postgresql.conf pg_hba.conf pg_hba.conf Reloading the configuration files Reloading the configuration files Managing connections Managing connections Roles Roles Database creation Privileges Extensions, p 36  Backup and restore Verboten practices

11 Extensions – B-tree What’s a b-tree? What’s a b-tree? Generalized binary trees – don’t often need balancing. Generalized binary trees – don’t often need balancing. See Wikipedia, or /~galles/visualization/B Tree.html for this animatio: See Wikipedia, or /~galles/visualization/B Tree.html for this animatio: /~galles/visualization/B Tree.html /~galles/visualization/B Tree.html btree_gist and btree_gin each add features. btree_gist and btree_gin each add features. Thursday topic

12 What do gist and gin do? Especially helpful for full-text searches. Especially helpful for full-text searches. Creating an index, is like: Creating an index, is like: CREATE INDEX name ON table USING gist( column ); CREATE INDEX name ON table USING gist( column ); The gist searches are “lossy” and the gin aren’t. The gist searches are “lossy” and the gin aren’t. See arch-indexes.html, See arch-indexes.html, arch-indexes.html arch-indexes.html Thursday topic

13 Extensions – fuzzy strings hstore addes key-value pair storage and index support, for “pseudonormalized” data. A medium between relational and NoSQL databases. hstore addes key-value pair storage and index support, for “pseudonormalized” data. A medium between relational and NoSQL databases. pg_trgm (trigram) is used with fuzzystrmatch, adding a new operator class for searches – 1LIKE and LIKE. pg_trgm (trigram) is used with fuzzystrmatch, adding a new operator class for searches – 1LIKE and LIKE. Thursday topic

14 Using hstore Make a table with hstore, then you can search on text within a larger field: Make a table with hstore, then you can search on text within a larger field: CREATE TABLE products ( id serial PRIMARY KEY, name varchar, attributes hstore ); INSERT INTO products (name, attributes) VALUES ( 'Geek Love: A Novel', 'author => "Katherine Dunn", pages => 368, category => fiction' ); Thursday topic

15 hstore vs JSON hstore – hstore – It only deals with text and It only deals with text and It’s not a full document store meaning you can’t nest objects. It’s not a full document store meaning you can’t nest objects. JSON - As you insert JSON into Postgres it will automatically ensure its valid JSON and error if its well not. JSON - As you insert JSON into Postgres it will automatically ensure its valid JSON and error if its well not. See e-vs-json/ See e-vs-json/ e-vs-json/ e-vs-json/ Thursday topic

16 Using pg_trgm A trigram is a group of three consecutive characters taken from a string. We can measure the similarity of two strings by counting the number of trigrams they share. A trigram is a group of three consecutive characters taken from a string. We can measure the similarity of two strings by counting the number of trigrams they share. This simple idea turns out to be very effective for measuring the similarity of words in many natural languages. This simple idea turns out to be very effective for measuring the similarity of words in many natural languages. Thursday topic

17 Using pg_trgm, cntd This query will return all values in the text column that are sufficiently similar to word, sorted from best match to worst. The index will be used to make this a fast operation even over very large data sets: This query will return all values in the text column that are sufficiently similar to word, sorted from best match to worst. The index will be used to make this a fast operation even over very large data sets: SELECT t, similarity(t, ' word ') AS sml FROM test_trgm WHERE t % ' word ' ORDER BY sml DESC, t; Thursday topic

18 Ch 3 – psql This is the command-line utility. This is the command-line utility. Environment variables Environment variables Importing and exporting data Importing and exporting data Basic reporting Basic reporting Ok – what can we try now? Ok – what can we try now?

19 Ch 4 – Using pgAdmin Features Features Connecting to a server Connecting to a server Navigating pgAdmin Navigating pgAdmin Creating asserts and setting privileges Creating asserts and setting privileges Import and export Import and export Backup and restore Backup and restore pgScript pgScript Graphical explain Job scheduling with pgAgent Try installing and using on Thursday?

20 Ch 5 – Data Types Numerics Numerics Serials Serials Generate series function Generate series function Characters and strings Characters and strings String functions String functions Splitting strings into arrays, tables, or substrings Splitting strings into arrays, tables, or substrings Regular expressions and pattern matching Regular expressions and pattern matching Temporals Temporals Time zones Time zones What they are and are not What they are and are not Datetime operators and functions Arrays  Range types  after Arrays JSON  after that XML Custom and composite data types What looks promising for your project?

21 Arrays Every PostgreSQL data type has a companion array type. Every PostgreSQL data type has a companion array type. E.g., character has a character array type character[]. E.g., character has a character array type character[]. Example usage with a table: Example usage with a table: CREATE TABLE rock_band ( name text, members text[] ) INSERT INTO rock_band VALUES ('Led Zeppelin', '{"Page", "Plant", "Jones", "Bonham"}' ) Thursday topic

22 Arrays, cntd You can then access, etc. via indexing: You can then access, etc. via indexing: postgres=# select members[1:2] from rock_band; members {Page,Plant} {Barrett,Gilmour} (2 rows) postgres=# select name from rock_band where 'Mason' = ANY (members); name Pink Floyd (1 row ) Thursday topic

23 Range types and operators SELECT employee FROM employment WHERE CURRENT_DATE GROUP BY employee; SELECT employee FROM employment WHERE CURRENT_DATE GROUP BY employee; SELECT numrange(11.1, 22.2) && numrange(20.0, 30.0); SELECT numrange(11.1, 22.2) && numrange(20.0, 30.0); Thursday topic

24 JSON Can extract, edit, and cast to JSON. Can extract, edit, and cast to JSON. row_to_json(row(1,'foo')) gives the result row_to_json(row(1,'foo')) gives the result{"f1":1,"f2":"foo"} select * from json_each('{"a":"foo", "b":"bar"}') gives the result select * from json_each('{"a":"foo", "b":"bar"}') gives the result key | value a | "foo" a | "foo" b | "bar" b | "bar" Thursday topic

25 Ref – Colorado State pdf – on Moodle Let’s just peruse what someone else’s intro to PostgreSQL looks like… Let’s just peruse what someone else’s intro to PostgreSQL looks like…

26 Comparison of PostgreSQL with MS SQL Server See, for example, See, for example, A comparison from the point of view of a data analyst A comparison from the point of view of a data analyst ts/2mhpwp/postgresql_vs_ms_sql_server_a_comp arison_of_two/ ts/2mhpwp/postgresql_vs_ms_sql_server_a_comp arison_of_two/ ts/2mhpwp/postgresql_vs_ms_sql_server_a_comp arison_of_two/ ts/2mhpwp/postgresql_vs_ms_sql_server_a_comp arison_of_two/ Reddit reviews! Reddit reviews!