I am unable to figure how to construct an Expr to pass to AddWhere method. Lets say I have a query like "SELECT * FROM product WHERE price < 500". Now how do I add "discount <= 10"? This is the closest I came to a solution:
left := sqlparser.NewStrVal([]byte("price"))
right := sqlparser.NewStrVal([]byte("?"))
comp := &sqlparser.ComparisonExpr{
Operator: sqlparser.LessEqualStr,
Left: left,
Right: right,
}
fmt.Printf("%v\n", sqlparser.String(comp))
sel := stmt.(*sqlparser.Select)
sel.AddWhere(comp)
fmt.Printf("%v\n", sqlparser.String(sel))
But this seems to quote the left in single quotes, because I assume it is considering it as a value instead of a column name. So how do I add a column name expr?
I am unable to figure how to construct an
Expr
to pass to AddWhere method. Lets say I have a query like "SELECT * FROM product WHERE price < 500". Now how do I add "discount <= 10"? This is the closest I came to a solution:But this seems to quote the left in single quotes, because I assume it is considering it as a value instead of a column name. So how do I add a column name expr?