Mastering Postgres
Introduction
Introduction to the course
Overview of course structure
Postgres vs. everyone
The psql CLI
Data Types
Introduction to schema
Integers
Numeric
Floating point
Storing money
NaNs and infinity
Casting types
Characters types
Check constraints
Domain types
Charsets and collations
Binary data
UUIDs
Boolean
Enums
Timestamps
Timezones
Dates and times
Advanced Data Types
Intervals
Serial type
Sequences
Identity
Network and mac addresses
JSON
Arrays
Generated columns
Text search types
Bit string
Ranges
Composite types
Nulls
Unique constraints
Exclusion constraints
Foreign key constraints
Indexing
Introduction to indexes
Heaps and CTIDs
B-Tree overview
Primary keys vs. secondary indexes
Primary key types
Where to add indexes
Index selectivity
Composite indexes
Composite range
Combining multiple indexes
Covering indexes
Partial indexes
Index ordering
Ordering nulls in indexes
Advanced Indexing
Functional indexes
Duplicate indexes
Hash indexes
Naming indexes
Understanding Query Plans
Introduction to explain
Explain structure
Scan nodes
Costs and rows
Explain analyze
Generating Results
Introduction to queries
Cross joins
Inner joins
Outer joins
Subqueries
Lateral joins
ROWS FROM
Filling gaps in sequences
Subquery elimination
Combining queries
Set generating functions
Indexing joins
Advanced SQL
Introduction to advanced SQL
Grouping
Grouping sets, rollups, cubes
Window functions
CTEs
CTEs with window functions
Recursive CTE
Hierarchical recursive CTE
Handling nulls
Row value syntax
Views
Materialized views
Removing duplicate rows
Upsert
Returning keyword
COALESCE + generated column
Full Text Search
Introduction to full text search
Searching with LIKE
Vectors, queries, and ranks
Websearch
Ranking
Indexing full text search
Highlighting
Advanced JSON
Intro to JSON
JSON vs JSONB
Validating JSON
Creating JSON objects + arrays
JSON extraction
JSON containment
JSON existence
JSON recordset
Updating JSON
Indexing JSON parts
GIN index
Vectors (pgvector)
Intro to pgvector
Vector embedding columns
Find related articles
Upsert vector embedding
Semantic search
Other operators
Vector indexes
Outro
Thank you
Bonus interviews
Heroku's glory days & Postgres vs the world (with Craig Kerstiens)
Creating a Postgres platform with Monica & Tudor from Xata.io
Bootstrapping an email service provider (with Jesse Hanley)
Locked video

Please purchase the course to watch this video.

Video thumbnail
Full Text Search
Introduction to full text search

Full Course

$
349
$399
USD, one-time fee
Aaron is a natural teacher and this course is the best introduction to Postgres I have come across. Lessons are easy to follow and he recommends some great tools for working with Postgres.
Joel Drumgoole
Joel Drumgoole

PostgreSQL database platform

Shorten dev cycles with branching and zero-downtime schema migrations.

Test Data

I've made my test data available for you to use and follow along.

Download
or
Use on Xata

Summary

Learn how to use Postgres for full-text search, which is great for most use cases before considering more advanced tools like Elasticsearch or Typesense. The video advises leveraging Postgres full-text search until your needs grow, especially if you need features like typo tolerance that Postgres can't handle. We explore working with movie data using `tsvectors` and GIN indexes to efficiently search and rank movie information.

Video Transcript

In this module, we're gonna cover default vanilla out of the box, full text search with Postgres. And I know what you're saying, 'Aaron, Elasticsearch exists, Typesense exists, MeiliSearch exists.' I agree. And all of those things are great. And in fact, if you're using a platform like Xata, then it automatically replicates all your data out to Elasticsearch and gives you that incredibly powerful search. You can absolutely do that.

My encouragement to you is going to be, push the Postgres full-text search until it doesn't work for you anymore. The place where it'll start to break down is either scale, you just have too much text that you need to search over or features/functionality. You might end up in a spot where you need something like typo tolerance and faceted search, and a lot of stuff that Postgres maybe doesn't support out of the box. Even if you can like finagle Postgres to do it, it might be better just to go with one of the tools that is dedicated to search. Because Postgres, by default is not dedicated to search. There are tools that are better for it. It's just a matter of, do you actually need those tools.

If you're at a somewhat reasonable scale and the full-text search works for you, that greatly simplifies your life and your stack. If you're not on something like Xata that handles all of that for you, then just staying in vanilla Postgres is gonna simplify your stack.

We're gonna cover tsvectors, tsqueries, rankings, GIN indexes, all of that kind of stuff. First, let me show you the data that we're working with, so in the next video we can jump right in. What we're working with is select * from movies, and this dataset came from Kaggle. I downloaded it as a CSV and just imported it. I will leave a link down below the video somewhere so you can grab this dataset for yourself. I have literally just imported it into this table and have done nothing else yet.

Let's take a look at this. I do want to see some movies that I recognize. We're gonna sort by release year here and I don't recognize any of those. 'The Lego Batman'. I recognize that one. Return of Xander Cage. Okay so, sorry, I got distracted. Here is this schema that we're working with, release year, title, origin director, the whole cast, genre, wiki, and then the plot.

I think what we're probably gonna end up searching over is the title and the plot. We're gonna try to search for some keywords. We're gonna try to rank them, maybe we'll rank them where newer movies come up higher because they're more likely to be known than the 'Kansas Saloon Smashers' from 1901, although that does sound interesting. This is the dataset that we're going to work with. Let's get started.