Hello, there is a simple task, make a selection of rows from a table and mark each selected row with the flag true ("viewed"). And the fields of the selected lines I need to read, and the flag must be set, so that next time not to stumble upon the processed lines. I think this task is often found in practice, I would like to know what they do in this case. I think that there is a better solution than simply selecting the lines, and then each line, in a loop, to do UPDATE SET viewed = true.
1 answer
For example, in Postgresql, you can do it like this:
UPDATE mytable SET viewed=true WHERE viewed<>true RETURNING * - Thank you, this is exactly what I was looking for. I wonder if there is a similar query in other databases with the return of modified rows, or is it just a PostgreSQL counter - Sergey Pysnik
- OUTPUT in MSSQL. In others I do not know. - AkaInq
|