Test UPDATE in Postgres

0

The idea is to do a search with the result of BEFORE, execute UPDATE with the appropriate changes and perform a new search with the DEPOIS, then undo all changes, a test for UPDATE.

SELECT id_evento, id_statusevento FROM syo_evento WHERE id_evento = 771678;
UPDATE syo_evento SET id_statusevento = 'CANCELADO' WHERE id_evento = 771678;
SELECT id_evento, id_statusevento FROM syo_evento WHERE id_evento = 771678;
ROLLBACK

It works, but in Datastudio 4.7 I only get the result of the first SELECT, while in pgAdmin 3 I do not get a result "Query result with 1 row discarded.", is there any way to do what I need?

    
asked by anonymous 12.01.2018 / 12:17

1 answer

-1

I got some results using Datastudio, I'm not interested in another tool, I use more than one database type and datastudio allows me to access all of them.

WITH alterados AS ( UPDATE syo_evento SET id_statusevento = 'CANCELADO' WHERE id_evento = 771678 RETURNING * )
SELECT '1-ANTES' as tipo, id_evento, id_statusevento FROM syo_evento WHERE id_evento = 771678
UNION ALL
SELECT '2-DEPOIS', id_evento, id_statusevento FROM alterados;
ROLLBACK

I do not know if it is ideal, it is possible that WITH has limitations of amount of data as there is in Sql Server, if you have any better idea please, thanks.

    
12.01.2018 / 12:26