Created
May 29, 2023 10:31
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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