How to query with formulas in a scalable way using generated columns

  Рет қаралды 2,240

Supabase

Supabase

Күн бұрын

Generated columns allow us to calculate a column based on other columns to create a new column for a table. They also allow us to index based on the column, which allows us to scale any query involving the column.
Often, queries involving complex formulas do not scale, but generated columns allow us to do so by allowing us to index the column. This can be used for financial analysis, sorting by profit margins, and many other applications. It also allows us to display latitude and longitude from PostGIS types, which works great in combination with Supabase realtime.
In this video, / dshukertjr explains how to create a generated column, how to use the generated column to run queries with complex mathematical formulas efficiently, and how to use the generated column in combination with Supabase realtime to display PostGIS data in the app.
Chapters
00:00 Intro
00:21 Explaining the scalability issue with formulas in a query
01:16 Using generated columns to solve the scalability issue
04:09 Using Supabase realtime and PostGIS with generated columns
06:30 Outro
💻 Videos to watch next:
▶ • Make your queries 43,2...
▶ • Getting started with P...
▶ • How to store and query...
👇 Learn more about Supabase 👇
🕸 Website: supabase.com/
🏁 Get started: app.supabase.com/
📄 Docs: supabase.com/docs
🔔 Subscribe for more tutorials and feature updates from Supabase: / @supabase
📱 Connect with Us:
🐙 Github: www.github.com/supabase
💬 Discord: www.discord.supabase.com/
🐦 Twitter: / supabase
▶ Instagram (follow for memes): / supabasecom
ABOUT SUPABASE:
Supabase is the open source Firebase alternative. Supabase provides a full Postgres database for every project with pgvector, backups, realtime, and more. Add and manage email and password, passwordless, OAuth, and mobile logins to your project through a suite of identity providers and APIs.
Build in a weekend, scale to millions.
#Supabase #AppDevelopment #RealtimeApps #DeveloperTools

Пікірлер: 32
@dshukertjr
@dshukertjr 12 күн бұрын
We are working on series of Postgres videos on this channel right now! What other Postgres concepts would you like us to cover? Let us know in the comments blow 👇
@DinoRossYT
@DinoRossYT Күн бұрын
More computing actions scenarios data oriented so we can take advantage of backend all-in-one 🙏
@brotherly9058
@brotherly9058 12 күн бұрын
Thanks very much for this!!!!❤❤
@dshukertjr
@dshukertjr 11 күн бұрын
Glad you liked it!
@powertipsweb
@powertipsweb 11 күн бұрын
Awesome, thank you for the quality content and great service you provide.❤
@luisandrade1291
@luisandrade1291 12 күн бұрын
I wish you had shown the execution time of the before and after.
@dshukertjr
@dshukertjr 12 күн бұрын
I only had 1000 rows in this particular example, but yes, I should have prepared enough sample data so that I could demonstrate the execution time difference. Trust me though, querying millions of rows with this formula in the query will take a very long time without using a generated column!
@Yusuf-ok5rk
@Yusuf-ok5rk 11 күн бұрын
hey these new videos of yours are pretty good. keep up the good work. Oh also imo you should add your name + any other person that worked in the video in description.
@dshukertjr
@dshukertjr 11 күн бұрын
Great suggestion! Let me add it in!
@shmuel-k
@shmuel-k 11 күн бұрын
Geberated columns are only able to access data from the current row. So you can't use them for rollup fields or to reference another table. If you need data from another table, you're back to triggers, functions, and views
@dshukertjr
@dshukertjr 11 күн бұрын
Yup, views are awesome!
@thibaultbarolat-massole7190
@thibaultbarolat-massole7190 12 күн бұрын
Great. Does it work with jsonb column?
@dshukertjr
@dshukertjr 12 күн бұрын
Yup, that is another awesome use case. You could extract certain values from jsonb columns as a generated column, or you could construct jsonb columns using other columns.
@jaguarconsultoriadigital8147
@jaguarconsultoriadigital8147 12 күн бұрын
Thanks very much.
@dshukertjr
@dshukertjr 12 күн бұрын
Glad to hear you liked it!
@fawazjoseph878
@fawazjoseph878 12 күн бұрын
Awesome feature 👏🏿🙌🏿 Can you create a generated column using the supabase ui column editor
@dshukertjr
@dshukertjr 12 күн бұрын
It's not quite yet supported, but hopefully in the future!
@mrrolandlawrence
@mrrolandlawrence Күн бұрын
persistant computed columns are awesome.
@akshykhade
@akshykhade 12 күн бұрын
i wasted so much time with triggers and functions for small tasks like this
@dshukertjr
@dshukertjr 12 күн бұрын
I have been there 😂
@champechilufya1458
@champechilufya1458 11 күн бұрын
Same here !!!!
@DinoRossYT
@DinoRossYT 8 күн бұрын
Same
@ubitubee
@ubitubee 11 күн бұрын
do one on different type of indexes and approximate string / natural language search
@dshukertjr
@dshukertjr 11 күн бұрын
Awesome suggestion! Will definitely cover the topic in the future!
@champechilufya1458
@champechilufya1458 11 күн бұрын
Is this new or has it always been there? I think computed columns might have always been a postgres thing, but this allows me to generate unique compound ids, which i can use in conflict upsert type queries. Glad i clicked
@dshukertjr
@dshukertjr 11 күн бұрын
It's relatively new as it was only introduced in Posgres 12, which was released in 2019.
@ubitubee
@ubitubee 11 күн бұрын
is there a difference, performance-wise, between this method and making functions with triggers?
@dshukertjr
@dshukertjr 11 күн бұрын
Performance-wise probably not. At least nothing significant.
@brotherly9058
@brotherly9058 17 сағат бұрын
How can we alter that column formula?
@DinoRossYT
@DinoRossYT 8 күн бұрын
So not trigger or functions anymore? 😅
@dshukertjr
@dshukertjr 2 күн бұрын
If your use case can be done using generated column, you probably should use generated columns, but triggers have more capabilities than generated column such as reaching out to other tables. So the answer is "it depends"!
@DinoRossYT
@DinoRossYT Күн бұрын
@@dshukertjr always on point, great example u made here 🙏
Are Multi-Column Indexes a good idea?
11:22
Supabase
Рет қаралды 2,1 М.
Универ. 10 лет спустя - ВСЕ СЕРИИ ПОДРЯД
9:04:59
Комедии 2023
Рет қаралды 2,8 МЛН
Tom & Jerry !! 😂😂
00:59
Tibo InShape
Рет қаралды 56 МЛН
Неприятная Встреча На Мосту - Полярная звезда #shorts
00:59
Полярная звезда - Kuzey Yıldızı
Рет қаралды 7 МЛН
I can’t believe they built this in React
16:08
Theo - t3․gg
Рет қаралды 57 М.
Supabase just shipped a LOT of cool stuff...
15:31
Davis Media
Рет қаралды 3,4 М.
Build an SQL Agent with Llama 3 | Langchain | Ollama
20:28
TheAILearner
Рет қаралды 2,3 М.
Learn 50 Data Analyst Concepts In 6 Minutes
6:02
Learn with Lukas
Рет қаралды 17 М.
8 things you should NEVER do in a Database!
22:56
Supabase
Рет қаралды 9 М.
React 19's useOptimistic: EVERYTHING you NEED to know
25:24
Jack Herrington
Рет қаралды 10 М.
Usage-based restrictions for SaaS subscription tiers
35:28
Supabase
Рет қаралды 6 М.
Learn to code with an unfair advantage.
15:05
Jason Goodison
Рет қаралды 165 М.
Firebase vs Supabase - I Built The Same App With Both
6:21
Your Average Tech Bro
Рет қаралды 91 М.
#miniphone
0:16
Miniphone
Рет қаралды 3,6 МЛН
1$ vs 500$ ВИРТУАЛЬНАЯ РЕАЛЬНОСТЬ !
23:20
GoldenBurst
Рет қаралды 1,3 МЛН
💅🏻Айфон vs Андроид🤮
0:20
Бутылочка
Рет қаралды 739 М.
Asus  VivoBook Винда за 8 часов!
1:00
Sergey Delaisy
Рет қаралды 1,1 МЛН