fork download
  1. import re
  2.  
  3. qry = '''
  4. with
  5. qry_1 as (
  6. SELECT ID,
  7. NAME
  8. FROM ( ... other code...
  9. ),
  10. qry_2 as (
  11. SELECT coalesce (table1.ID, table2.ID) as ID,
  12. NAME
  13. FROM (...other code...
  14. ),
  15. qry_3 as (
  16. SELECT id.WEATHER AS WEATHER_MORN,
  17. ROW_NUMBER() OVER(PARTITION BY id.SUN
  18. ORDER BY id.TIME) AS SUN_TIME,
  19. id.RAIN,
  20. id.MIST
  21. FROM (...other code..
  22. )
  23. '''
  24.  
  25. find_params = [
  26. re.findall('^\w+|NAME|(?<=\.)NAME', i) for i in
  27. re.findall(r"^\S+\sas\s*\(\s*((?:\n.*)*?)\n\s*FROM\b", qry, re.MULTILINE | re.IGNORECASE)
  28. ]
  29.  
  30. print(find_params)
Success #stdin #stdout 0.02s 9556KB
stdin
Standard input is empty
stdout
[['NAME'], ['NAME'], []]