0

I have an similar problem to: converting a list of integers into range in python But i have a small difference. I have realtively large mariadb database where i have a table of jobs to be done:

Table:

CREATE TABLE blocks (
block_num   INTEGER,
data_state  TINYINT,
PRIMARY KEY(block_num));

Every entry for which data_state is Null the block_num has to be processed by a python function.

SELECT  block_num FROM blocks
where data_state IS NULL

I have two options how to handle the jobs. One is using one Function which processes one entry and one which can process a bulk of entries, which is considerably faster. The bulk needs to be a range for that to happen. Is there a way in sql to return a list containing the range like in converting a list of integers into range in python ?

If i would do that in python i'd either make very many requests to the database or would need to import the whole table as list into python, which would be very inefficient and slow.

Edit: Each number is unique and all numbers are created by the rule xn=xn+1

List:

Block_num data_state
1         Null
2         Null
3         1
4         Null
5         Null
6         1
7         1
8         1

it could be that the ranges where data_state is NULL is about 100 entries in row.

Min : 1

Max : large (like 1000000)

scientes
  • 1
  • 2
  • how is this range defined? You've only got one number in your blocks table. So how do you define the first and second numbers in each range instance? It's not clear. – ADyson Oct 31 '17 at 13:14
  • 1
    You'd be wise to [edit] your question to show some example input data and a corresponding example output resultset. Most SO people won't try to reverse-engineer your question by looking at the question you linked. – O. Jones Oct 31 '17 at 13:17
  • Take a look at this. It may help you. https://www.xaprb.com/blog/2006/03/22/find-contiguous-ranges-with-sql/ – O. Jones Oct 31 '17 at 13:21
  • Thanks that should help. – scientes Oct 31 '17 at 13:27
  • min(list) .. max(list) ?? – Rick James Nov 05 '17 at 20:22

0 Answers0