Format implements the NodeFormatter interface.
(ctx *FmtCtx)
| 495 | |
| 496 | // Format implements the NodeFormatter interface. |
| 497 | func (node *ComparisonExpr) Format(ctx *FmtCtx) { |
| 498 | opStr := node.Operator.String() |
| 499 | // IS and IS NOT are equivalent to IS NOT DISTINCT FROM and IS DISTINCT |
| 500 | // FROM, respectively, when the RHS is true or false. We prefer the less |
| 501 | // verbose IS and IS NOT in those cases. |
| 502 | if node.Operator == IsDistinctFrom && (node.Right == DBoolTrue || node.Right == DBoolFalse) { |
| 503 | opStr = "IS NOT" |
| 504 | } else if node.Operator == IsNotDistinctFrom && (node.Right == DBoolTrue || node.Right == DBoolFalse) { |
| 505 | opStr = "IS" |
| 506 | } |
| 507 | if node.Operator.HasSubOperator() { |
| 508 | binExprFmtWithParenAndSubOp(ctx, node.Left, node.SubOperator.String(), opStr, node.Right) |
| 509 | } else { |
| 510 | binExprFmtWithParen(ctx, node.Left, opStr, node.Right, true) |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | // NewTypedComparisonExpr returns a new ComparisonExpr that is verified to be well-typed. |
| 515 | func NewTypedComparisonExpr(op ComparisonOperator, left, right TypedExpr) *ComparisonExpr { |
nothing calls this directly
no test coverage detected