What I want: if record with the same unique(doctor_id, year, month) exists, we need to increase sum
via input sum
value.
I’m trying this SQL query:
with rows as (
insert into mis_doctor_stats (doctor_id, year, month, sum)
values (1, 2025, 3, 100),
(1, 2021, 4, 6)
on conflict (doctor_id, year, month) do update set sum = mis_doctor_stats.sum + excluded.sum
returning id)
insert
into mis_doctor_stats_files(file_id, stats_id)
select 4, rows.id
from rows;
But still got the error: FROM expected, got ‘;’
screenshot
2
Answers
As @Bruno strictly said the problem was in the
alias_name
for which I tried to use reserved keywordrows
.The right solution in my case:
can you remove semicolon at the end?