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
Searching with LIKE

Full Course

$
349
$399
USD, one-time fee
Window function ๐Ÿ˜Š. CTE with window function ๐Ÿ˜ฎ. Hierarchical recursive CTE ๐Ÿคฏ. Recommended all the way. Canโ€™t wait to see the rest of the videos!
M Wildan Zulfikar
M Wildan Zulfikar

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 the `LIKE` and `ILIKE` operators for basic text searches in Postgres, with a demonstration on performing case-insensitive searches using `ILIKE` in a movie database. While these operators are useful for small-scale queries, they become inefficient with larger datasets. The video also introduces more efficient solutions, like `tsquery` and `tsvector`, for handling full-text searches.

Video Transcript

The first thing we're gonna cover is using the LIKE and the ILIKE operators, and this is not a good way to build a full text search engine, but it is a way to search text. We're gonna cover it very quickly before we move on to tsquery and tsvector.

Coming back to select * from movies. If we take a look at these and I just wanna order by releaseyear desc, 'cause I think I'm always going to want to see that. Let's order by releaseyear desc and let's do releaseyear desc, title desc. Let's do it like that. Okay, so now, we have a pretty stable set of movies here and let's just go ahead and search for, tsk, (sharply inhales) let's search for Oregon.

If we wanted to search for Oregon, just kind of like naively, we could say where title LIKE, and then we could put these parentheses, sorry, these percent marks, and say '%Oregon%', if you can spell Oregon. That's gonna bring back all of the movies where the title contains Oregon. Now, here's the problem. If either the data was entered, the data was entered incorrectly or more likely, the user just says, hey, I just wanna see Oregon, your host, because like is in fact case-sensitive, which is in my opinion, kind of a bummer. But you do have ILIKE. If you have ILIKE there, then you're okay, you're back to a case in sensitive search. This is better than nothing, right?

If you're just searching, for example, like an email column or just even just the title column, you might be able to get away with this. A username, something like that, doing an ILIKE with these are wild cards here. Doing the ILIKE with the wild card is acceptable. Now, once you start getting into, okay, I wanna look in the plot as well, then you start having to do stuff like or plot ilike. You come up here and you say '%Oregon%' as well and see now we're starting, now we're already at half a second or more, and it's just on 35,000 rows. It's just not that big of a table.

You're already starting to feel like this is not a good solution. This is not the search engine solution that we're going to go with. I did wanna show you this, because LIKE and ILIKE can be valuable in other situations. It can be extremely valuable, especially if you wanna say like, hey, this string needs to start or this column needs to start with the string or again, and nobody does. Or it needs to end with the string or again, which there you go, that movie actually and the title actually ends in Oregon. You can use that more likely on a like an email column or a username column. We're gonna move on from this, 'cause this is not really full text search.