Created
October 29, 2016 15:56
-
-
Save Dviejopomata/9592795f160a5ae994c3cad52967cd51 to your computer and use it in GitHub Desktop.
upsert en postgres
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
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