Skip to content

Instantly share code, notes, and snippets.

@pvh
Last active December 11, 2015 17:28
Show Gist options
  • Save pvh/4634543 to your computer and use it in GitHub Desktop.
Save pvh/4634543 to your computer and use it in GitHub Desktop.
Postgres: The Bits You Haven't Found talk
A Beastiary of Badassery
-
SQLisms
--
WITH
arrays and unnest
window functions
JSON
row types
selects in the target list
full-text search
range types
reading EXPLAIN
exclusion constraints
LISTEN/NOTIFY
intervals and time
generate_series
CASE WHEN pivots
coalesce
Extensia
--
hstore
dblink
uuid-ossp
pgcrypto
tablefunc?
pl/v8
postgis
pppppsql!
--
\d*+
\i
\e
\x
URL support
Performance/Operations
--
CONCURRENTLY
GIN/GIST
knn
application_name
pg_stat_activity
pg_stat_statements
pg_locks
pg_statio
pg_cancel_backend
sync commit
pg_stat_replication
Index only scans
BONUS ROUND
-
9.3's a comin'
lateral joins
SUPERJSON
foreign data wrappers (more than french hip-hop)
background (database!) workers
(other?)
@xzilla
Copy link

xzilla commented Jan 25, 2013

!
.psqlrc

and for those more adventurous, you can do things like:
echo '*postgres`namespace_search_path /s' | mdb -p 18883

@gorthx
Copy link

gorthx commented Jan 25, 2013

\set [alias] '[query I use often]';

in psql, use :alias to call the query.

@msakrejda
Copy link

  • CASE in aggregates for a quickie alternative to a full pivot
  • Also, fancy JOIN conditions: inequality, LIKE, function calls, etc.

@fdr
Copy link

fdr commented Jan 25, 2013

Also, fancy JOIN conditions: inequality, LIKE, function calls, etc.

Also, unfancy ones:

SELECT * FROM users JOIN address ON users.id = 1 AND users.id = address.user_id;

@quarterdome
Copy link

@pvh - awesome list! Arrays and unnest came very handy and timely for us here!

I was wondering if there is postgres feature that I am overlooking that could help with this problem: https://gist.github.com/4669408

@trentrichardson
Copy link

POSIX Regular expressions are not common in every db, expecially with an easy comparison operator like "~" (not to be confused with LIKE):

select * from users where first_name ~ '.*thomas.*'

http://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-POSIX-TABLE

@msakrejda
Copy link

depesz's article on variables, especially custom variable classes, is interesting.

@petergeoghegan
Copy link

When talking about interval and time handling, don't forget to emphasize how Postgres magically does the right thing with interval arithmetic in the face of timezones, DST, etc. Apparently that is a real differentiator, and I think it nicely illustrates the general Postgres ethos of putting a lot of effort into getting these details right, so the user doesn't have to.

inet types that have many operators (including bitwise operators), so you can do arithmetic with them, and calculate appropriate bitmasks. You could also have declarative constraints enforced using them.

fuzzystrmatch is kind of interesting, though I'm not sure it should make the cut.

Partially indexes. This is something that Instagram use extensively. Maybe mention create index concurrently in passing.

@pvh
Copy link
Author

pvh commented Feb 26, 2013

From CK: \pset null, already found it handy - craigkerstiens.com/2013/02/21/mor… and +1 to \set [alias] [query]

@kelsin
Copy link

kelsin commented Feb 27, 2013

The \set commands can be used not just for full queries. I use to save some that ended with something like 'where order_id = ' and would then run it with something like :order 2342523; Worked great.

@wesdotcool
Copy link

@pvh I saw you speak at Waza yesterday. Your talk and slides were great! Thanks for the info!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment