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

Method Format

postgres/parser/sem/tree/datum.go:1867–1884  ·  view source on GitHub ↗

Format implements the NodeFormatter interface.

(ctx *FmtCtx)

Source from the content-addressed store, hash-verified

1865
1866// Format implements the NodeFormatter interface.
1867func (d *DEnum) Format(ctx *FmtCtx) {
1868 if ctx.HasFlags(fmtStaticallyFormatUserDefinedTypes) {
1869 s := DBytes(d.PhysicalRep)
1870 // We use the fmtFormatByteLiterals flag here so that the bytes
1871 // get formatted as byte literals. Consider an enum of type t with physical
1872 // representation \x80. If we don't format this as a bytes literal then
1873 // it gets emitted as '\x80':::t. '\x80' is scanned as a string, and we try
1874 // to find a logical representation matching '\x80', which won't exist.
1875 // Instead, we want to emit b'\x80'::: so that '\x80' is scanned as bytes,
1876 // triggering the logic to cast the bytes \x80 to t.
1877 ctx.WithFlags(ctx.flags|fmtFormatByteLiterals, func() {
1878 s.Format(ctx)
1879 })
1880 } else {
1881 s := DString(d.LogicalRep)
1882 s.Format(ctx)
1883 }
1884}
1885
1886func (d *DEnum) String() string {
1887 return AsString(d)

Callers

nothing calls this directly

Calls 4

DBytesTypeAlias · 0.85
DStringTypeAlias · 0.85
WithFlagsMethod · 0.80
HasFlagsMethod · 0.45

Tested by

no test coverage detected