Read-only coherent database scan

I would like to execute a select query that returns a lot of data in the database. The specified database forces me to split my queries into pieces of 10,000 results with an offset + limit. While I iterate over these pieces, someone else is updating the database, which in some cases may cause db to return the same row several times. I handle this with a post-processing filter that removes rows with duplicate identifiers, but I wonder if there is a way to create a set of sql queries that allows me to get a consistent view of the database across multiple select statements. i.e. BEGIN + COMMIT, but for choice.

Did I mention that I am not a sql user?

+6
source share
1 answer

You can not:

Order them by ID, get the first 10000, get the LAST id.

The second time, the filter around the larger LAST id, getting the next 10000.

Do the same before you complete

Select top(10000) * from Table order by id 

get last id

 Select top(10000) * from Table where id> LAST order by id 

LAST, of course, replaced by a number

Very low, but should fix the problem and eliminate duplicates

+1
source

Source: https://habr.com/ru/post/913111/


All Articles