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

Function ParseDBool

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

ParseDBool parses and returns the *DBool Datum value represented by the provided string, or an error if parsing is unsuccessful. See https://github.com/postgres/postgres/blob/90627cf98a8e7d0531789391fd798c9bfcc3bc1a/src/backend/utils/adt/bool.c#L36

(s string)

Source from the content-addressed store, hash-verified

169// string, or an error if parsing is unsuccessful.
170// See https://github.com/postgres/postgres/blob/90627cf98a8e7d0531789391fd798c9bfcc3bc1a/src/backend/utils/adt/bool.c#L36
171func ParseDBool(s string) (*DBool, error) {
172 s = strings.TrimSpace(s)
173 if len(s) >= 1 {
174 switch s[0] {
175 case 't', 'T':
176 if isCaseInsensitivePrefix(s, "true") {
177 return DBoolTrue, nil
178 }
179 case 'f', 'F':
180 if isCaseInsensitivePrefix(s, "false") {
181 return DBoolFalse, nil
182 }
183 case 'y', 'Y':
184 if isCaseInsensitivePrefix(s, "yes") {
185 return DBoolTrue, nil
186 }
187 case 'n', 'N':
188 if isCaseInsensitivePrefix(s, "no") {
189 return DBoolFalse, nil
190 }
191 case '1':
192 if s == "1" {
193 return DBoolTrue, nil
194 }
195 case '0':
196 if s == "0" {
197 return DBoolFalse, nil
198 }
199 case 'o', 'O':
200 // Just 'o' is ambiguous between 'on' and 'off'.
201 if len(s) > 1 {
202 if isCaseInsensitivePrefix(s, "on") {
203 return DBoolTrue, nil
204 }
205 if isCaseInsensitivePrefix(s, "off") {
206 return DBoolFalse, nil
207 }
208 }
209 }
210 }
211 return nil, makeParseError(s, types.Bool, pgerror.New(pgcode.InvalidTextRepresentation, "invalid bool value"))
212}
213
214// ParseDByte parses a string representation of hex encoded binary
215// data. It supports both the hex format, with "\x" followed by a

Callers 1

ParseAndRequireStringFunction · 0.85

Calls 3

NewFunction · 0.92
isCaseInsensitivePrefixFunction · 0.85
makeParseErrorFunction · 0.85

Tested by

no test coverage detected