MCPcopy Create free account
hub / github.com/dolthub/doltgresql / Format

Method Format

postgres/parser/sem/tree/insert.go:47–93  ·  view source on GitHub ↗

Format implements the NodeFormatter interface.

(ctx *FmtCtx)

Source from the content-addressed store, hash-verified

45
46// Format implements the NodeFormatter interface.
47func (node *Insert) Format(ctx *FmtCtx) {
48 ctx.FormatNode(node.With)
49 if node.OnConflict.IsUpsertAlias() {
50 ctx.WriteString("UPSERT")
51 } else {
52 ctx.WriteString("INSERT")
53 }
54 ctx.WriteString(" INTO ")
55 ctx.FormatNode(node.Table)
56 if node.Columns != nil {
57 ctx.WriteByte('(')
58 ctx.FormatNode(&node.Columns)
59 ctx.WriteByte(')')
60 }
61 if node.DefaultValues() {
62 ctx.WriteString(" DEFAULT VALUES")
63 } else {
64 ctx.WriteByte(' ')
65 ctx.FormatNode(node.Rows)
66 }
67 if node.OnConflict != nil && !node.OnConflict.IsUpsertAlias() {
68 ctx.WriteString(" ON CONFLICT")
69 if len(node.OnConflict.Columns) > 0 {
70 ctx.WriteString(" (")
71 ctx.FormatNode(&node.OnConflict.Columns)
72 ctx.WriteString(")")
73 }
74 if node.OnConflict.ArbiterPredicate != nil {
75 ctx.WriteString(" WHERE ")
76 ctx.FormatNode(node.OnConflict.ArbiterPredicate)
77 }
78 if node.OnConflict.DoNothing {
79 ctx.WriteString(" DO NOTHING")
80 } else {
81 ctx.WriteString(" DO UPDATE SET ")
82 ctx.FormatNode(&node.OnConflict.Exprs)
83 if node.OnConflict.Where != nil {
84 ctx.WriteByte(' ')
85 ctx.FormatNode(node.OnConflict.Where)
86 }
87 }
88 }
89 if HasReturningClause(node.Returning) {
90 ctx.WriteByte(' ')
91 ctx.FormatNode(node.Returning)
92 }
93}
94
95// DefaultValues returns true iff only default values are being inserted.
96func (node *Insert) DefaultValues() bool {

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected