MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / SQL

Method SQL

pkg/sql/ast/sql.go:157–186  ·  view source on GitHub ↗

SQL returns the SQL representation of this binary expression. The operator, left, and right sub-expressions are serialized in infix notation. NOT-qualified operators (LIKE, ILIKE, SIMILAR TO) are rendered as "x NOT OP y".

()

Source from the content-addressed store, hash-verified

155// The operator, left, and right sub-expressions are serialized in infix notation.
156// NOT-qualified operators (LIKE, ILIKE, SIMILAR TO) are rendered as "x NOT OP y".
157func (b *BinaryExpression) SQL() string {
158 if b == nil {
159 return ""
160 }
161 left := exprSQL(b.Left)
162 right := exprSQL(b.Right)
163 op := b.Operator
164 if b.CustomOp != nil {
165 op = b.CustomOp.String()
166 }
167
168 upperOp := strings.ToUpper(op)
169
170 // Handle IS NULL / IS NOT NULL (right side is NULL literal)
171 if upperOp == "IS NULL" || upperOp == "IS NOT NULL" {
172 return fmt.Sprintf("%s %s", left, upperOp)
173 }
174
175 // Handle special operators like LIKE, ILIKE, SIMILAR TO
176 if b.Not {
177 switch upperOp {
178 case "LIKE", "ILIKE", "SIMILAR TO":
179 return fmt.Sprintf("%s NOT %s %s", left, upperOp, right)
180 default:
181 return fmt.Sprintf("NOT (%s %s %s)", left, op, right)
182 }
183 }
184
185 return fmt.Sprintf("%s %s %s", left, op, right)
186}
187
188// SQL returns the SQL representation of this unary expression.
189// Prefix operators (NOT, +, -, etc.) are prepended; the PostgreSQL

Callers

nothing calls this directly

Calls 2

exprSQLFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected