diff --git a/redash/query_runner/query_results.py b/redash/query_runner/query_results.py index e0e7a9b7..4e4ed613 100644 --- a/redash/query_runner/query_results.py +++ b/redash/query_runner/query_results.py @@ -43,7 +43,7 @@ def _guess_type(value): def extract_query_ids(query): - queries = re.findall(r'(?:join|from) query_(\d+)', query, re.IGNORECASE) + queries = re.findall(r'(?:join|from)\s+query_(\d+)', query, re.IGNORECASE) return [int(q) for q in queries] diff --git a/tests/query_runner/test_query_results.py b/tests/query_runner/test_query_results.py index e4241ad2..bde09e22 100644 --- a/tests/query_runner/test_query_results.py +++ b/tests/query_runner/test_query_results.py @@ -19,6 +19,10 @@ class TestExtractQueryIds(TestCase): query = "SELECT * FROM query_123 JOIN query_4566" self.assertEquals([123, 4566], extract_query_ids(query)) + def test_finds_queries_with_whitespace_characters(self): + query = "SELECT * FROM query_123 a JOIN\tquery_4566 b ON a.id=b.parent_id JOIN\r\nquery_78 c ON b.id=c.parent_id" + self.assertEquals([123, 4566, 78], extract_query_ids(query)) + class TestCreateTable(TestCase): def test_creates_table_with_colons_in_column_name(self):