Syntax error in postgress functions

Hi there, I'm very new to this whole database thing and thought that supabase seemed not so intimidating. I am however running into a problem. I'm following this tutorial https://www.youtube.com/watch?v=I6nnp9AINJk because just like he shows in the video I want to increment a value. I'm pretty sure I've followed the guide to a tee, yet supabase is giving me a syntax error and it's really not that helpful because it's just saying at or around variable name. Maybe one of the more advanced users could point out where the problem occurs ๐Ÿ™
declare
  new_amount int;
begin 
  select amount 
  into new_amount
  from public.collection
  where id = card_id

  new_amount = new_amount + 1;

  update public.collection
  set amount = new_amount
  where id = card_id;

  return new_amount;
end

I've set the argument to be card_id.

The specific error is: Failed to create function: failed to create pg.functions: syntax error at or near "new_amount"
YouTubeSupabase
For the introductory video on PostgreSQL functions, check out ๐Ÿ‘‰ https://www.youtube.com/watch?v=MJZCCpCYEqk

Sometimes we have a collection of complex steps we need to perform in a particular sequence from the front-end. Maybe we want to execute an SQL statement that the supabase-js library does not yet support. These are both excellent use case...
Was this page helpful?