STILLWATER;
07/19/2022, 1:35 PMNeedle
07/19/2022, 1:35 PMSTILLWATER;
07/19/2022, 1:35 PMSTILLWATER;
07/19/2022, 1:36 PMsql
create function update_story_count(uid uuid, change_value int)
returns void
language plpgsql
as
$$
BEGIN
(
UPDATE "Users" U
SET stories_count = stories_count + change_value
WHERE U.id=uid
);
END
$$;STILLWATER;
07/19/2022, 1:36 PMSTILLWATER;
07/19/2022, 1:37 PMreturn query (...)STILLWATER;
07/19/2022, 1:37 PMSTILLWATER;
07/19/2022, 1:37 PMSTILLWATER;
07/19/2022, 1:37 PMSTILLWATER;
07/19/2022, 1:37 PMSTILLWATER;
07/19/2022, 1:37 PMSTILLWATER;
07/19/2022, 1:51 PMSTILLWATER;
07/19/2022, 1:51 PMSTILLWATER;
07/19/2022, 1:51 PMsilentworks
07/19/2022, 2:23 PMsql stable there is no need for plpsql since you aren't using any of its features in this query. But your existing code should work too by just removing the brackets. I tested this and it worked for me.
sql
create function update_story_count(uid uuid, change_value int)
returns void
language plpgsql
as
$$
BEGIN
UPDATE "Users" U
SET stories_count = stories_count + change_value
WHERE U.id = uid;
END
$$;STILLWATER;
07/19/2022, 2:23 PMSTILLWATER;
07/19/2022, 2:28 PMsilentworks
07/19/2022, 2:28 PMSTILLWATER;
07/19/2022, 2:28 PMsilentworks
07/19/2022, 2:28 PMSTILLWATER;
07/19/2022, 2:28 PMsilentworks
07/19/2022, 2:28 PMSTILLWATER;
07/19/2022, 2:28 PMSTILLWATER;
07/19/2022, 2:29 PMsilentworks
07/19/2022, 2:29 PMSTILLWATER;
07/19/2022, 2:29 PMsilentworks
07/19/2022, 2:29 PMSTILLWATER;
07/19/2022, 2:29 PMsilentworks
07/19/2022, 2:29 PMsilentworks
07/19/2022, 2:30 PMSTILLWATER;
07/19/2022, 2:30 PMsilentworks
07/19/2022, 2:58 PM.rpc call but it works inside the SQL editor
sql
create or replace function update_story_count(uid uuid, change_value int)
returns TABLE (id uuid, stories_count int)
as
$$
UPDATE "Users" U
SET stories_count = stories_count + change_value
WHERE U.id = uid
RETURNING U.id, U.stories_count; -- tells it which data to return
$$
language sql; -- changed to sql instead of plpsqlSTILLWATER;
07/19/2022, 3:02 PMsilentworks
07/19/2022, 3:03 PMplpgsql specific feature in hereSTILLWATER;
07/19/2022, 3:03 PMSTILLWATER;
07/19/2022, 3:17 PMSTILLWATER;
07/19/2022, 3:17 PMSTILLWATER;
07/19/2022, 3:17 PMsilentworks
07/19/2022, 3:18 PMplpgsql right?STILLWATER;
07/19/2022, 3:18 PMsilentworks
07/19/2022, 3:18 PMSTILLWATER;
07/19/2022, 3:18 PMSTILLWATER;
07/19/2022, 3:18 PMsilentworks
07/19/2022, 3:18 PMSTILLWATER;
07/19/2022, 3:20 PMSTILLWATER;
07/19/2022, 3:20 PMSTILLWATER;
07/19/2022, 3:20 PMSTILLWATER;
07/19/2022, 3:21 PMsilentworks
07/19/2022, 3:57 PMSTILLWATER;
07/19/2022, 3:58 PM