5
I need to capture only the clause where
several queries to analyze the filters used.
For example:
select "DIM_1"."col1",
"DIM_2"."col2" ,
"DIM_3"."col3" ,
"DIM_4"."col4" ,
"FAT_1"."col5"
from "FAT_1",
"DIM_1",
"DIM_2",
"DIM_3",
"DIM_4"
where "DIM_1"."col1" IS NOT NULL
AND "DIM_2"."col2" LIKE ('SUCCESS')
AND "DIM_3"."col3" BETWEEN 20161213 AND 20161222
AND "DIM_4"."col4" > 0
I created a list with SQL, and then tried applying regular expressions to extract the Where part, but unsuccessfully, follows below what I tried:
`for line in sql:`
`if re.search(r'[where]\W',line):`
`where.append(line)`
Unfortunately I could not extract only the part of Where, can tell me what mistake I made and how to fix?
Follows a regex that returns the Where clause:
(?:WHERE\s|ORDER BY\s|GROUP BY\s|\Z)(.*)
. For it to work, the command needs to be all in one line. See if this helps you– Victor Tadashi
Regex to get the Where clause when the sql command is idented:
(?:WHERE\s|ORDER BY\s|GROUP BY\s|\Z)([^\n]*\n+)+(.*)
– Victor Tadashi