Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Is Postgres the Future of Open SQL

Is Postgres the Future of Open SQL

What are some of the unique features in postgres that make it so sweet?

Harold Giménez

March 30, 2013
Tweet

More Decks by Harold Giménez

Other Decks in Technology

Transcript

  1. Brief history of the project Durability Data types Query constructs

    Advanced Indexing Extensions Concurrency Is Postgres the future of Open SQL?
  2. In the beginning... 1977 - 1985: "Ingres" 1986 - 1994:

    "Postgres" 1995: Postgres95 1996: PostgreSQL 6.0, an open source project.
  3. Data types timestamptz interval ranges enums geom inet, cidr, macaddr

    xml json array money tsvector text char date, timestamp uuid boolean numeric types
  4. CREATE TABLE users( id uuid primary key DEFAULT uuid_generate_v4(), name

    text not null, tags text[], properties hstore, last_seen_from inet, created_at timestamptz ); http://www.postgresql.org/docs/current/static/datatype.html
  5. SELECT * FROM users WHERE tags @> ['beer', 'cheeseburgers']; SELECT

    name, unnest(tags) as tag FROM users WHERE name = 'hgmnz'; http://www.postgresql.org/docs/current/static/arrays.html
  6. SELECT * FROM users WHERE properties -> 'city' = 'Austin'

    http://www.postgresql.org/docs/current/static/hstore.html
  7. WITH active_users AS ( SELECT * FROM users WHERE active

    ), recent_events AS ( SELECT * FROM events WHERE created_at > now() - interval '1 day' ) SELECT * FROM active_users JOIN recent_events WHERE recent_events.name = 'eat_cheeseburger'; http://www.postgresql.org/docs/current/static/queries-with.html
  8. WITH moved_rows AS ( DELETE FROM events WHERE date >=

    '2013-02-01' AND date < '2013-03-01' RETURNING * ) INSERT INTO event_logs SELECT * FROM moved_rows;
  9. SELECT meal, lead(meal, 1) OVER (PARTITION BY user_id ORDER BY

    created_at) AS next_meal FROM meals; http://www.postgresql.org/docs/current/static/tutorial-window.html http://www.postgresql.org/docs/current/static/functions-window.html
  10. CREATE INDEX idx_active_user_names ON users(name) WHERE active; CREATE INDEX idx_user_age

    ON users(age(now(), dob)); CREATE INDEX idx_user_properties ON users(properties) USING gist; CREATE INDEX CONCURRENTLY ...; https://devcenter.heroku.com/articles/postgresql-indexes
  11. Useful Extensions PostGIS Procedural Languages (eg: plv8) Data Types Foreign

    Data Wrappers CREATE EXTENSION hstore; CREATE LANGUAGE plv8; CREATE EXTENSION postgis; CREATE EXTENSION redis_fdw;
  12. Side projects to high performance apps Fully managed Followers Forks

    Dataclips Continuous Protection Run vanilla Postgres, always.