Testing UPDATE in Postgres

Asked

Viewed 149 times

1

The idea is to do a search with the BEFORE result, run UPDATE with the appropriate changes and run a new search with DEPOIS, then undo all the 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 don’t get "Query result with 1 Row discarded." there is some way to do what I need ?

  • 3

    Missed using the begin before you update to initiate a transaction.

1 answer

-1

I got some results using Datastudio, I have no interest in another tool, use more of a type bank 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 don’t know if it’s ideal, it’s possible that the WITH have data quantity limitations just like there are in Sql Server, if you have a better idea feel free, thank you.

  • I think you need to read this here and this here.

  • @Lacobus, I don’t understand how this helps me, I need to see the "before and after" of the update, I should use as a real proof for larger updates, being better in the datastudio, because I can work in several types of banks. If you want to exemplify in reply please feel free, thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.