AmusedGrape
03/18/2022, 1:40 PMsyntax error at or near "insert"
sql
create function commands_inc (x int, row_id text)
returns void as
$$
insert into command_logs (id, commands) values (row_id, x) on conflict do update
$$
language plpgsql volatile;
what am i doing wrong? thanks!Avin
03/18/2022, 1:52 PMBEGIN
and END
statements.Avin
03/18/2022, 1:54 PMsql
as
create function commands_inc (x int, row_id text)
returns void as
$$
insert into command_logs (id, commands) values (row_id, x) on conflict do update set commands = commands + x;
$$
language sql volatile;
Avin
03/18/2022, 1:57 PMwhere
clause for the do update, also.AmusedGrape
03/18/2022, 2:01 PMAmusedGrape
03/18/2022, 2:02 PMsql
create function commands_inc (x int, row_id text)
returns void as
$$
if (select * from bot_analytics where timestamp > now() - interval '1 week') then
update bot_analytics set commands = commands + x where bot = row_id
else
insert into bot_analytics (commands, bot) values (x, row_id)
end
$$
language plpgsql volatile;
AmusedGrape
03/18/2022, 2:02 PMif
Avin
03/18/2022, 2:03 PMAmusedGrape
03/18/2022, 2:03 PMsql
create function commands_inc (x int, row_id text)
returns void as
$$
BEGIN
if (select * from bot_analytics where timestamp > now() - interval '1 week') then
update bot_analytics set commands = commands + x where bot = row_id;
else
insert into bot_analytics (commands, bot) values (x, row_id);
end;
END;
$$
language plpgsql volatile;
or in the if statements?Avin
03/18/2022, 2:04 PMend if
AmusedGrape
03/18/2022, 2:05 PM