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

Function ParseAndRequireString

postgres/parser/sem/tree/parse_string.go:66–132  ·  view source on GitHub ↗

ParseAndRequireString parses s as type t for simple types. Arrays and collated strings are not handled. The dependsOnContext return value indicates if we had to consult the ParseTimeContext (either for the time or the local timezone).

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

Source from the content-addressed store, hash-verified

64// The dependsOnContext return value indicates if we had to consult the
65// ParseTimeContext (either for the time or the local timezone).
66func ParseAndRequireString(
67 t *types.T, s string, ctx ParseTimeContext,
68) (d Datum, dependsOnContext bool, err error) {
69 switch t.Family() {
70 case types.ArrayFamily:
71 d, dependsOnContext, err = ParseDArrayFromString(ctx, s, t.ArrayContents())
72 case types.BitFamily:
73 d, err = ParseDBitArray(s)
74 case types.BoolFamily:
75 d, err = ParseDBool(s)
76 case types.BytesFamily:
77 d, err = ParseDByte(s)
78 case types.DateFamily:
79 d, dependsOnContext, err = ParseDDate(ctx, s)
80 case types.DecimalFamily:
81 d, err = ParseDDecimal(s)
82 case types.FloatFamily:
83 d, err = ParseDFloat(s)
84 case types.INetFamily:
85 d, err = ParseDIPAddrFromINetString(s)
86 case types.IntFamily:
87 d, err = ParseDInt(s)
88 case types.IntervalFamily:
89 itm, typErr := t.IntervalTypeMetadata()
90 if typErr != nil {
91 return nil, false, typErr
92 }
93 d, err = ParseDIntervalWithTypeMetadata(s, itm)
94 case types.Box2DFamily:
95 d, err = ParseDBox2D(s)
96 case types.GeographyFamily:
97 d, err = ParseDGeography(s)
98 case types.GeometryFamily:
99 d, err = ParseDGeometry(s)
100 case types.JsonFamily:
101 d, err = ParseDJSON(s)
102 case types.OidFamily:
103 i, err := ParseDInt(s)
104 if err != nil {
105 return nil, false, err
106 }
107 d = NewDOid(*i)
108 case types.StringFamily:
109 // If the string type specifies a limit we truncate to that limit:
110 // 'hello'::CHAR(2) -> 'he'
111 // This is true of all the string type variants.
112 if t.Width() > 0 {
113 s = truncateString(s, int(t.Width()))
114 }
115 return NewDString(s), false, nil
116 case types.TimeFamily:
117 d, dependsOnContext, err = ParseDTime(ctx, s, TimeFamilyPrecisionToRoundDuration(t.Precision()))
118 case types.TimeTZFamily:
119 d, dependsOnContext, err = ParseDTimeTZ(ctx, s, TimeFamilyPrecisionToRoundDuration(t.Precision()))
120 case types.TimestampFamily:
121 d, dependsOnContext, err = ParseDTimestamp(ctx, s, TimeFamilyPrecisionToRoundDuration(t.Precision()))
122 case types.TimestampTZFamily:
123 d, dependsOnContext, err = ParseDTimestampTZ(ctx, s, TimeFamilyPrecisionToRoundDuration(t.Precision()), time.Local)

Callers 2

parseElementMethod · 0.85
ResolveAsTypeMethod · 0.85

Calls 15

ParseDArrayFromStringFunction · 0.85
ParseDBitArrayFunction · 0.85
ParseDBoolFunction · 0.85
ParseDByteFunction · 0.85
ParseDDateFunction · 0.85
ParseDDecimalFunction · 0.85
ParseDFloatFunction · 0.85
ParseDIntFunction · 0.85
ParseDBox2DFunction · 0.85
ParseDGeographyFunction · 0.85

Tested by

no test coverage detected