import re
pat = r"COALESCE\((.*?)\)"
s = "select DISTINCT SUM(case when t0_0.pp is not null  then COALESCE(t0_0.pp,0)\nelse 0 end) from inventory_coverage_view t0_0 where  LOWER(t0_0.h) ='vg' AND t0_0.id = '9'"
m = re.search(pat, s)
if m:
	print(m.group(1))
