Skip to content

Instantly share code, notes, and snippets.

@JohnBra
Created May 29, 2023 10:31
Show Gist options
  • Save JohnBra/1d8067606d75ce32cc2197ecc15baf08 to your computer and use it in GitHub Desktop.
Save JohnBra/1d8067606d75ce32cc2197ecc15baf08 to your computer and use it in GitHub Desktop.
A simple function to increment a number on a postgres database like Supabase
drop function increment_views;
create function increment_views(post_slug text)
returns setof public.posts as
$$
update public.posts
set views = views + 1
where slug = post_slug;
select * from public.posts where slug = post_slug;
$$
language sql volatile;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment