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

Method consumeInt

pkg/sql/sem/tree/interval.go:92–122  ·  view source on GitHub ↗

Consumes the next integer.

()

Source from the content-addressed store, hash-verified

90
91// Consumes the next integer.
92func (l *intervalLexer) consumeInt() int64 {
93 if l.err != nil {
94 return 0
95 }
96
97 start := l.offset
98
99 // Advance offset to prepare a valid argument to ParseInt().
100 if l.offset < len(l.str) && (l.str[l.offset] == '-' || l.str[l.offset] == '+') {
101 l.offset++
102 }
103 for ; l.offset < len(l.str) && l.str[l.offset] >= '0' && l.str[l.offset] <= '9'; l.offset++ {
104 }
105 // Check if we have something like ".X".
106 if start == l.offset && len(l.str) > (l.offset+1) && l.str[l.offset] == '.' {
107 return 0
108 }
109
110 x, err := strconv.ParseInt(l.str[start:l.offset], 10, 64)
111 if err != nil {
112 l.err = pgerror.Newf(
113 pgcode.InvalidDatetimeFormat, "interval: %v", err)
114 return 0
115 }
116 if start == l.offset {
117 l.err = pgerror.Newf(
118 pgcode.InvalidDatetimeFormat, "interval: missing number at position %d: %q", start, l.str)
119 return 0
120 }
121 return x
122}
123
124// Consumes the next unit.
125func (l *intervalLexer) consumeUnit(skipCharacter byte) string {

Callers 2

consumeNumMethod · 0.95
iso8601ToDurationFunction · 0.95

Calls 1

NewfFunction · 0.92

Tested by

no test coverage detected