---
title: Database enums are weird
url: "https://aaronfrancis.com/videos/database-enums-are-weird"
path: "/videos/database-enums-are-weird"
type: video
author: Aaron Francis
published: 2023-10-10
topic: Databases
keywords: [enum, database enums, storing enums, ordering by enums, integer storage, min max enums, modifying enums, mysql enums, enum constraints, enum gotchas, planetscale]
youtube_url: "https://www.youtube.com/watch?v=ej8jzMloE_4"
site_index: "/llms.txt"
keyword_index: "/llms/keywords.txt"
---

# Database enums are weird

## Chapters

- What enums are
- The orders table
- Storing enums as integers
- Ordering by enums
- The MIN/MAX exception
- Modifying an enum

## Transcript

**Aaron Francis:** I was reading the docs yesterday. This is a true story. This is not a bit. MySQL documentation. And I came across something that really surprised me. It had to do with the MAX function and the way that the MAX function interacts with ENUMS. And honestly, it was not what I expected. So we'll look at the, the right down the middle use case of ENUMS, and then I'll talk about some of the weird things and things you have to look out for.

**Aaron Francis:** ENUM is short for enumeration or enumerated list, and so it's a column type where you have a set defined list, and you get to read it as a string. So as a human, you can look at it and see a list of strings, but the database looks at it and sees a list of integers. And so the storage on disk is really compact, even though you get the readability of a string.

**Aaron Francis:** That's kind of awesome. You get a little bit of data validation because you can only choose one of the items from the list. But there are a few weird things about ENUMS that we're gonna look at. This is very much a right down the middle use case right here. You've got your orders table with a size column, which is an ENUM, and then these are the legal values that can go in that column.

**Aaron Francis:** One of these five values is the only thing that is allowed, extra small, small, medium, large, extra large. So you get this little bit of data validation from MySQL that the user has chosen a legal option. So let's create this table, and then we'll insert into orders just the size, and we'll insert a small.

**Aaron Francis:** Sounds good. And then if we read that back, we see the small was inserted, right? Interesting video. Thumbs up. Please like and subscribe. Like, that's... Who cares about that, right? But what is interesting is I told you, you get the readability of a string with the underlying storage of an integer. So is there a way to prove that?

**Aaron Francis:** You better believe that there is. So we'll select size, and then we'll select size plus zero, which is gonna just coerce it into the underlying integer. And we'll see that the label is small, but the integer is actually two. What if we were to insert, let's do an extra small, an extra large, and a large, and then we were to read these back?

**Aaron Francis:** You'll see that we have all these different underlying integers. Where do these integers come from? Let's go ahead and sort by that integer value. These integers are the position that we originally declared the ENUM column with. So extra small was declared first, so it got item or ID number one, position number one.

**Aaron Francis:** Small was two. Jumping to the end, extra large was the fifth item in the list, and so its underlying integer is five, even if the label is extra large. Why does this matter? Well, because when you order, when you order by an ENUM, it orders by the underlying integer and not the string.

**Aaron Francis:** So if we say select size from orders order by size, you'll see this, and this looks very bizarre, doesn't it? These two Xs, in my mind, those should go together. If I'm ordering by size, I would expect the two Xs to be ordered near each other.

**Aaron Francis:** But if we turn this back on, we'll see it's actually ordering, it's actually ordering by that integer, and so this makes a lot more sense. So this was the first surprise to me with ENUMS. This is not the most surprising part. This is the first surprise, is that when you order, you could get back a list that looks unordered, but in fact is ordered by a thing you cannot see unless you do this weird type juggling thing that we did, right?

**Aaron Francis:** This may be exactly what you're looking for. If you need to order a list in a specific order, an ENUM is great for that. Just make sure that you declare it in the order that you want it ordered. The thing that actually surprised me, the thing that I discovered in the docs was if you put a MAX or MIN function on it, for some reason, instead of using the underlying integer, it uses the string for that.

**Aaron Francis:** So you're ordering by the underlying integer, but if you run a MAX over it, it uses the string. That is... It makes no sense to me. Let me see if I can prove this one to you. If we were to say select MAX size from orders, based on everything we just learned about ordering, you think it would be extra large because that's position number five. In fact, it's extra small because alphabetically, that is the max string.

**Aaron Francis:** That is the biggest string. That is the string latest in the alphabet, even though it is in position number one. So ENUMS, kind of weird, right? Feels a little bit inconsistent to me to have the ordering work on the underlying integer and the MAX, MIN to work on the display string. But hey, if it's fine with you, it's fine with me. They're really powerful.

**Aaron Francis:** They're really useful. There's one other thing that you'll need to remember, and that's that you cannot add a new option. You cannot change the options at all without altering the schema of your table, and that can be kind of a pain. If that is a pain, you might consider PlanetScale. We have zero downtime migrations. But you do need to keep that in mind.

**Aaron Francis:** So that's a, that's one strike against it, uh, as compared to a character column or even just an integer column, is you would have to alter that table. I hope that this was helpful to you. I read every single comment, and so does my boss, so please enumerate the reasons you liked this video, and let me know what you want to see next. You can find us at planetscale.com/youtube.

**Aaron Francis:** Until next time, see ya.

---

## Related on aaronfrancis.com

- [PHP doesn't suck (anymore)](/podcast/php-doesnt-suck-anymore-yfnsj0) *(Podcast · 2023-09-15 · shared: enum, planetscale)*
- [Store 8 feature flags in 1 integer (Bitwise operations in MySQL)](/videos/store-8-feature-flags-in-1-integer-bitwise-operations-in-mysql) *(Video · 2023-11-09 · shared: integer storage, planetscale)*
- [Aaron Francis Is Laravel's New VP of Marketing & Community](/podcast/aaron-francis-is-laravels-new-vp-of-marketing-community-485b13ef) *(Podcast · 2026-08-04 · shared: planetscale)*
- [Do The Hardest Thing with Jesse Hanley](/podcast/do-the-hardest-thing-with-jesse-hanley-9b42d310) *(Podcast · 2026-05-26 · shared: planetscale)*
- [Two new YouTube channels for Database School](/newsletter/two-new-youtube-channels-for-database-school) *(Newsletter · 2025-09-26 · shared: planetscale)*

## Relevant Resources from Aaron Francis

- **[MySQL for Developers](https://databaseschool.com)** (overview on site: [/courses](/courses)): Full video course covering MySQL indexing, deferred joins, pagination, query plans, and schema design for application developers.
- **[Mastering Postgres](https://databaseschool.com)** (overview on site: [/courses](/courses)): Deep-dive video course on PostgreSQL indexing, query performance, JSONB, full-text search, locking, and production operations.

## Search aaronfrancis.com (2-Hop Static Keyword Index)

Pick the alphabetical shard matching any topic to find exact pages across all articles, newsletters, videos, talks, and podcast transcripts (every shard is < 40 KB):
[A-B](/llms/keywords/a-b.txt) · [C](/llms/keywords/c.txt) · [D-E](/llms/keywords/d-e.txt) · [F-G](/llms/keywords/f-g.txt) · [H-J](/llms/keywords/h-j.txt) · [K-L](/llms/keywords/k-l.txt) · [M-N](/llms/keywords/m-n.txt) · [O-P](/llms/keywords/o-p.txt) · [Q-R](/llms/keywords/q-r.txt) · [S](/llms/keywords/s.txt) · [T-Z](/llms/keywords/t-z.txt) · [Directory](/llms/keywords.txt) · [Site Map](/llms.txt)

Shards for this page's topics: `enum` ([D-E](/llms/keywords/d-e.txt)), `storing enums` ([S](/llms/keywords/s.txt)), `ordering by enums` ([O-P](/llms/keywords/o-p.txt)), `integer storage` ([H-J](/llms/keywords/h-j.txt)).

## About Aaron Francis (Current Context)

Aaron Francis is VP of Marketing and Community at [Laravel](https://laravel.com), founder of [Try Hard Studios](https://tryhardstudios.com), creator of [Solo](https://soloterm.com), co-host of [Mostly Technical](/podcast), and author of [Mastering Postgres](/courses), [High Performance SQLite](/courses), [MySQL for Developers](/courses), and [Screencasting.com](/courses). Full bio: [/about](/about) · Current focus: [/now](/now).
