Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
upsert en postgres
INSERT INTO app.messervicio as acum(id, NUMEROCOBROS, IMPORTECOBROS, ant, cargo, abono, actual, aaaa, mm, idservicios, idfactuaaaamm)
select idfactuaaaamm || '-' || idservicios id,
count(*) NUMEROCOBROS,
sum(monto) IMPORTECOBROS,
0,0,0,0,
aaaa,mm,
idservicios,
idfactuaaaamm
from app.cobros a
where a.idfactuaaaamm = '201301'
group by
idfactuaaaamm || '-' || idservicios,
aaaa,mm,
idservicios,
idfactuaaaamm
ON CONFLICT (id)
do UPDATE SET NUMEROCOBROS = acum.NUMEROCOBROS+ EXCLUDED.NUMEROCOBROS, importecobros = acum.importecobros + EXCLUDED.IMPORTECOBROS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.