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
Vectors (pgvector)
Intro to pgvector

Full Course

$
349
$399
USD, one-time fee
The course "Mastering Postgres" helped me practice query commands and understand why they're important. Inspiring me to explore the 'why' and 'how' behind each one. Truly a great course!
Nakolus
Nakolus

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 pgvector, a powerful Postgres extension designed for working with AI advancements. pgvector allows you to store vector embeddings—long lists of numbers representing items like images or text—and use them to compare similarities, enhancing recommendations and search functionalities. By the end of the module, you'll install pgvector, create and query vector columns, and perform tasks like nearest neighbor searches within Postgres, all without requiring an additional database.

Video Transcript

In this module, we're going to look at pgvector. Pgvector is a Postgres extension of which there are hundreds. We're not going to look at all of them, but we are going to look at pgvector. It's one of the most popular, and it's especially relevant these days because of all the advances in AI.

pgvector can help you store vector embeddings and then query against them. Now, what is a vector embedding? Great question. A vector embedding is basically a long array of floating point numbers. It's kinda wild, but basically the premise is you have an image or a document or a blob of text and you send it off to some AI model. That could be OpenAI, that could be Gemini, that could be Llama, it could be any AI model.

What you get back is a long string of floating point numbers. What those numbers represent is a little bit opaque, but it helps you determine similarity. If you have a vector embedding and then you have a search term, or you have another image, you can turn those into vector embeddings and then compare the embeddings to see if it's similar. This can drive features like recommended next article or if you're e-commerce, a recommended product that you might want to add to your cart based on what is already in your cart. Stuff like that. It can also help with searching. We talked about full text search, but you can have a little bit fuzzier, kinda like sentiment search, that sort of thing with you when you have vector embeddings. We're going to look at pgvector.

We'll start by getting it installed, making sure it's working, creating some vector columns, querying against those columns, doing some nearest neighbor searching, that kind of stuff. Then finally adding some indexes at the end. Pgvector is very broad, it is very robust. We will look at the write down at the middle use case for it. There are dozens of ways to tune it that are a little bit outside of the scope of this module, but you will come away from this module being able to implement pgvector, vector embedding, vector searches, all of that kind of stuff. In Postgres, you do not need a separate vector database. Postgres can do it all.