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

Method Format

pkg/sql/sem/tree/insert.go:28–78  ·  view source on GitHub ↗

Format implements the NodeFormatter interface.

(ctx *FmtCtx)

Source from the content-addressed store, hash-verified

26
27// Format implements the NodeFormatter interface.
28func (node *Insert) Format(ctx *FmtCtx) {
29 ctx.FormatNode(node.With)
30 if node.OnConflict.IsUpsertAlias() {
31 ctx.WriteString("UPSERT")
32 } else {
33 ctx.WriteString("INSERT")
34 }
35 ctx.WriteString(" INTO ")
36 ctx.FormatNode(node.Table)
37 if node.Columns != nil {
38 ctx.WriteByte('(')
39 ctx.FormatNode(&node.Columns)
40 ctx.WriteByte(')')
41 }
42 if node.DefaultValues() {
43 ctx.WriteString(" DEFAULT VALUES")
44 } else {
45 ctx.WriteByte(' ')
46 ctx.FormatNode(node.Rows)
47 }
48 if node.OnConflict != nil && !node.OnConflict.IsUpsertAlias() {
49 ctx.WriteString(" ON CONFLICT")
50 if node.OnConflict.Constraint != "" {
51 ctx.WriteString(" ON CONSTRAINT ")
52 ctx.FormatNode(&node.OnConflict.Constraint)
53 }
54 if len(node.OnConflict.Columns) > 0 {
55 ctx.WriteString(" (")
56 ctx.FormatNode(&node.OnConflict.Columns)
57 ctx.WriteString(")")
58 }
59 if node.OnConflict.ArbiterPredicate != nil {
60 ctx.WriteString(" WHERE ")
61 ctx.FormatNode(node.OnConflict.ArbiterPredicate)
62 }
63 if node.OnConflict.DoNothing {
64 ctx.WriteString(" DO NOTHING")
65 } else {
66 ctx.WriteString(" DO UPDATE SET ")
67 ctx.FormatNode(&node.OnConflict.Exprs)
68 if node.OnConflict.Where != nil {
69 ctx.WriteByte(' ')
70 ctx.FormatNode(node.OnConflict.Where)
71 }
72 }
73 }
74 if HasReturningClause(node.Returning) {
75 ctx.WriteByte(' ')
76 ctx.FormatNode(node.Returning)
77 }
78}
79
80// DefaultValues returns true iff only default values are being inserted.
81func (node *Insert) DefaultValues() bool {

Callers

nothing calls this directly

Calls 4

DefaultValuesMethod · 0.95
HasReturningClauseFunction · 0.85
FormatNodeMethod · 0.80
IsUpsertAliasMethod · 0.80

Tested by

no test coverage detected