Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
PostgreSQL Hstore
Search
Matthew Rudy Jacobs
May 09, 2012
Technology
8
1.8k
PostgreSQL Hstore
Talk at Codeaholics Hong Kong
Wednesday 9th May 2012
Matthew Rudy Jacobs
May 09, 2012
Tweet
Share
More Decks by Matthew Rudy Jacobs
See All by Matthew Rudy Jacobs
From Developer to Architect (and back again)
matthewrudy
3
220
Humans are Hard
matthewrudy
0
130
[Alpha] Humans Are Hard
matthewrudy
0
90
From Developer To Architect
matthewrudy
0
70
Git Commit Signing: Code we can trust?
matthewrudy
0
170
We Need To Talk About Postgres
matthewrudy
0
83
Coding as a Team At GoGoVan
matthewrudy
3
420
10 Years of Code
matthewrudy
0
100
Elixir - Part 1
matthewrudy
1
180
Other Decks in Technology
See All in Technology
SDカードフォレンジック
su3158
1
660
Oracle Cloud Infrastructure:2025年4月度サービス・アップデート
oracle4engineer
PRO
0
240
PagerDuty×ポストモーテムで築く障害対応文化/Building a culture of incident response with PagerDuty and postmortems
aeonpeople
3
490
持続可能なドキュメント運用のリアル: 1年間の成果とこれから
akitok_
1
250
OpsJAWS34_CloudTrailLake_for_Organizations
hiashisan
0
210
新卒エンジニアがCICDをモダナイズしてみた話
akashi_sn
2
270
クラウド開発環境Cloud Workstationsの紹介
yunosukey
0
210
MySQL Indexes and Histograms – How they really speed up your queries
lefred
0
120
AndroidアプリエンジニアもMCPを触ろう
kgmyshin
2
510
GraphQLを活用したリアーキテクチャに対応するSLI/Oの再設計
coconala_engineer
0
160
AIコーディングの最前線 〜活用のコツと課題〜
pharma_x_tech
4
2.9k
Aspire をカスタマイズしよう & Aspire 9.2
nenonaninu
0
320
Featured
See All Featured
Measuring & Analyzing Core Web Vitals
bluesmoon
7
400
Speed Design
sergeychernyshev
29
920
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
The Invisible Side of Design
smashingmag
299
50k
Designing for Performance
lara
608
69k
Reflections from 52 weeks, 52 projects
jeffersonlam
349
20k
It's Worth the Effort
3n
184
28k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
YesSQL, Process and Tooling at Scale
rocio
172
14k
The Straight Up "How To Draw Better" Workshop
denniskardys
233
140k
Documentation Writing (for coders)
carmenintech
69
4.7k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.8k
Transcript
PostgreSQL hstore Codeaholics.hk - Tuesday 8th May 2012 @MatthewRudy
Jason Crane isn’t here
a Coder • has a name • has a location
• has a github (optional) • has a twitter (optional)
NoSQL?
Mongo { "name": "Matthew Rudy", "location": "Hong Kong", "twitter": "@matthewrudy",
"github": "matthewrudy" }
Split the location { "name": "Matthew Rudy", "location_id": ObjectId("abc"), "twitter":
"@matthewrudy", "github": "matthewrudy" } { "_id": ObjectId("abc"), "name": "Hong Kong" }
Requirements Grow! • Coders have Projects • Coders have commits
on Projects • Projects have Categories • How many commits does @MatthewRudy have on PHP projects?
Isn’t this all a bit relational?
NoSQL?
No, SQL!
PostgreSQL CREATE TABLE coders ( name text NOT NULL, location_id
integer NOT NULL REFERENCES locations, github text, twitter text );
Optional Fields • ('matthewrudy', '@matthewrudy') • ('matthewrudy', NULL) • (NULL,
'@matthewrudy') • (NULL, NULL)
Find MatthewRudy on Github • SELECT * FROM coders WHERE
github = “matthewrudy”;
How many Coders have Github accounts? • SELECT COUNT(*) FROM
coders WHERE github IS NOT NULL;
How many Coders have Github and Twitter? • SELECT COUNT(*)
FROM coders WHERE github IS NOT NULL AND twitter IS NOT NULL;
How many Coders have Github OR Twitter? • SELECT COUNT(*)
FROM coders WHERE github IS NOT NULL OR twitter IS NOT NULL;
How many HKers have Github and Twitter? • SELECT COUNT(*)
FROM coders WHERE github IS NOT NULL AND twitter IS NOT NULL AND location_id = 2;
hstore! • CREATE EXTENSION hstore; • SELECT 'github=>"matthewrudy", twitter=>"@matthewrudy"'::hstore;
value of key • (column -> ‘key’)::text • (column ->
‘key’)::integer • (column -> ‘key’)::date
has key? • column ? key • column ?& ARRAY[‘key1’,
‘key2’] • column ?| ARRAY[‘key1’, ‘key2’]
Indexes • CREATE INDEX hcoders_identities ON hcoders USING GIST(identities);
PostgreSQL hstore CREATE TABLE hcoders ( name text NOT NULL,
location_id integer NOT NULL REFERENCES locations, identities hstore );
Optional Fields • 'github=>"matthewrudy", 'twitter=>"@matthewrudy"' • 'github=>"matthewrudy"' • 'twitter=>"@matthewrudy"' •
''
Find MatthewRudy on Github • SELECT * FROM coders WHERE
(identities -> ‘github’)::text = “matthewrudy”;
Find MatthewRudy on Github • SELECT * FROM coders WHERE
identities @> ‘github=>matthewrudy’
How many Coders have Github accounts? • SELECT COUNT(*) FROM
coders WHERE identities ? ‘github';
How many Coders have Github and Twitter? • SELECT COUNT(*)
FROM coders WHERE identities ?& ARRAY[‘github’, ‘twitter’];
How many Coders have Github OR Twitter? • SELECT COUNT(*)
FROM coders WHERE identities ?| ARRAY[‘github’, ‘twitter’];
How many HKers have Github and Twitter? • SELECT COUNT(*)
FROM coders WHERE identities ?& ARRAY[‘github’, ‘twitter’] AND location_id = 2;
Available on Heroku PG9.1 beta now!
@matthewrudy Please don’t stalk me!
Codeaholics http://groups.google.com/group/codeaholics