课程: Supabase Essential Training

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Custom PostgreSQL functions

Custom PostgreSQL functions

- [Instructor] Beyond commands like INSERT, SELECT, UPDATE, and DELETE, PostgreSQL has functions that make it easier to work with data before it is returned. And you can even create your own functions to suit your own needs. Let's take a look at how we can do this with the purchases table. So first, let's take a look at the data that is in this table. I'm going to do SELECT * FROM purchases, and then I'm going to run that query. We've got a sheet pan and a knife here, and each with a separate price. Now, let's say we wanted to get a sum of all the purchases. All we have to do is SELECT sum of the price_cents field. And with that in place, I'm going to run that. And now we have the sum, it is $22. So even though we don't have this grand total column in the table, or we're not storing it anywhere in the database, we're able to generate this information and return it. This is really helpful. We don't have to store the information and maintain it. We know we can always generate it using…

内容