Friday, June 08. 2012Finding contiguous primary keysPrinter FriendlyRecommended Books: PostgreSQL: Up and Running PostGIS in Action
Comments
Display comments as
(Linear | Threaded)
Any tips on how to adjust the example to ignore small breaks? Like if missing we have: 200, 400, 401. And I want the results to be:
1 to 399 and 402 to ...
I think if you change the n1 CTE that will do it. So for example:
change n1 to: n1 AS (SELECT n AS start_n FROM s EXCEPT SELECT n + i AS start_n FROM s CROSS JOIN generate_series(1,2) As i) Would give me a range of 1 999 for this test The number 2 you would replace with the largest gap you want to allow. |
Entry's LinksQuicksearchCalendar
Categories
Blog Administration |
Tracked: Jul 01, 20:52