How to extract all the conditions inside a where #3227
-
| 
         Hello If I have a select * from X where (A=1 orB=2) and C=3 or at least Hw should I proceed ?  | 
  
Beta Was this translation helpful? Give feedback.
      
      
          Answered by
          
            georgesittas
          
      
      
        Mar 26, 2024 
      
    
    Replies: 1 comment 1 reply
-
| 
         Perhaps something like this works, at least if your  >>> import sqlglot
>>>
>>> ast = sqlglot.parse_one("select * from X where (A=1 or B=2) and C=3")
>>> for cond in ast.args["where"].this.flatten():
...     print(cond.sql())
...
A = 1 OR B = 2
C = 3 | 
  
Beta Was this translation helpful? Give feedback.
                  
                    1 reply
                  
                
            
      Answer selected by
        tobymao
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Perhaps something like this works, at least if your
WHEREfilters are in normal form (either CNF or DNF):