Skip to content

How to change only certain conditions in complex where clause #426

Closed Answered by georgesittas
g-u-t-h-m-a-n asked this question in Q&A
Discussion options

You must be logged in to vote

The following seems to work correctly for your example, but I'm not sure if it's what you're after:

from sqlglot import exp, parse_one

def transformer(node):
    if isinstance(node, exp.Predicate):
        if 'XXX' in node.text('this') or 'XXX' in node.text('expression'):
            return parse_one("1=1")
    return node

print(parse_one(<your query>).transform(transformer).sql(pretty=True))

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@g-u-t-h-m-a-n
Comment options

Answer selected by tobymao
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants