MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / ParseAndRequireString

Function ParseAndRequireString

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

ParseAndRequireString parses s as type t for simple types. The dependsOnContext return value indicates if we had to consult the ParseContext (either for the time or the local timezone).

(
	t *types.T, s string, ctx ParseContext,
)

Source from the content-addressed store, hash-verified

31// The dependsOnContext return value indicates if we had to consult the
32// ParseContext (either for the time or the local timezone).
33func ParseAndRequireString(
34 t *types.T, s string, ctx ParseContext,
35) (d Datum, dependsOnContext bool, err error) {
36 switch t.Family() {
37 case types.ArrayFamily:
38 d, dependsOnContext, err = ParseDArrayFromString(ctx, s, t.ArrayContents())
39 case types.BitFamily:
40 r, err := ParseDBitArray(s)
41 if err != nil {
42 return nil, false, err
43 }
44 d = FormatBitArrayToType(r, t)
45 case types.BoolFamily:
46 d, err = ParseDBool(strings.TrimSpace(s))
47 case types.BytesFamily:
48 d, err = ParseDByte(s)
49 case types.DateFamily:
50 d, dependsOnContext, err = ParseDDate(ctx, s)
51 case types.DecimalFamily:
52 d, err = ParseDDecimal(strings.TrimSpace(s))
53 case types.FloatFamily:
54 d, err = ParseDFloat(strings.TrimSpace(s))
55 case types.INetFamily:
56 d, err = ParseDIPAddrFromINetString(s)
57 case types.IntFamily:
58 d, err = ParseDInt(strings.TrimSpace(s))
59 case types.IntervalFamily:
60 itm, typErr := t.IntervalTypeMetadata()
61 if typErr != nil {
62 return nil, false, typErr
63 }
64 d, err = ParseDIntervalWithTypeMetadata(intervalStyle(ctx), s, itm)
65 case types.PGLSNFamily:
66 d, err = ParseDPGLSN(s)
67 case types.PGVectorFamily:
68 d, err = ParseDPGVector(s)
69 case types.RefCursorFamily:
70 d = NewDRefCursor(s)
71 case types.Box2DFamily:
72 d, err = ParseDBox2D(s)
73 case types.GeographyFamily:
74 d, err = ParseDGeography(s)
75 case types.GeometryFamily:
76 d, err = ParseDGeometry(s)
77 case types.JsonFamily:
78 d, err = ParseDJSON(s)
79 case types.JsonpathFamily:
80 d, err = ParseDJsonpath(s)
81 case types.OidFamily:
82 if t.Oid() != oid.T_oid && s == UnknownOidName {
83 d = NewDOidWithType(UnknownOidValue, t)
84 } else {
85 d, err = ParseDOidAsInt(s)
86 }
87 case types.CollatedStringFamily:
88 d, err = NewDCollatedString(s, t.Locale(), ctx.GetCollationEnv())
89 case types.StringFamily:
90 s = truncateString(s, t)

Callers 4

parseElementMethod · 0.85
ResolveAsTypeMethod · 0.85
parseElementMethod · 0.85

Calls 15

ParseDArrayFromStringFunction · 0.85
ParseDBitArrayFunction · 0.85
FormatBitArrayToTypeFunction · 0.85
ParseDBoolFunction · 0.85
ParseDByteFunction · 0.85
ParseDDateFunction · 0.85
ParseDDecimalFunction · 0.85
ParseDFloatFunction · 0.85
ParseDIntFunction · 0.85
intervalStyleFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…