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

Method Format

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

Format implements the NodeFormatter interface.

(ctx *FmtCtx)

Source from the content-addressed store, hash-verified

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