MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / Format

Method Format

pkg/sql/sem/tree/expr.go:1630–1654  ·  view source on GitHub ↗

Format implements the NodeFormatter interface.

(ctx *FmtCtx)

Source from the content-addressed store, hash-verified

1628
1629// Format implements the NodeFormatter interface.
1630func (node *AnnotateTypeExpr) Format(ctx *FmtCtx) {
1631 if ctx.HasFlags(FmtPGAttrdefAdbin) {
1632 ctx.FormatNode(node.Expr)
1633 switch node.Type.Family() {
1634 case types.StringFamily, types.CollatedStringFamily:
1635 // Postgres formats strings using a cast afterward. Let's do the same.
1636 ctx.WriteString("::")
1637 ctx.WriteString(node.Type.SQLString())
1638 }
1639 return
1640 }
1641 switch node.SyntaxMode {
1642 case AnnotateShort:
1643 exprFmtWithParen(ctx, node.Expr)
1644 ctx.WriteString(":::")
1645 ctx.WriteString(node.Type.SQLString())
1646
1647 default:
1648 ctx.WriteString("ANNOTATE_TYPE(")
1649 ctx.FormatNode(node.Expr)
1650 ctx.WriteString(", ")
1651 ctx.WriteString(node.Type.SQLString())
1652 ctx.WriteByte(')')
1653 }
1654}
1655
1656// TypedInnerExpr returns the AnnotateTypeExpr's inner expression as a TypedExpr.
1657func (node *AnnotateTypeExpr) TypedInnerExpr() TypedExpr {

Callers

nothing calls this directly

Calls 5

exprFmtWithParenFunction · 0.85
FormatNodeMethod · 0.80
FamilyMethod · 0.80
SQLStringMethod · 0.80
HasFlagsMethod · 0.45

Tested by

no test coverage detected