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

Function ParseAndRequireString

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

ParseAndRequireString parses s as type t for simple types. Arrays and collated strings are not handled.

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

Source from the content-addressed store, hash-verified

20// ParseAndRequireString parses s as type t for simple types. Arrays and collated
21// strings are not handled.
22func ParseAndRequireString(t *types.T, s string, ctx ParseTimeContext) (Datum, error) {
23 switch t.Family() {
24 case types.ArrayFamily:
25 return ParseDArrayFromString(ctx, s, t.ArrayContents())
26 case types.BitFamily:
27 return ParseDBitArray(s)
28 case types.BoolFamily:
29 return ParseDBool(s)
30 case types.BytesFamily:
31 return ParseDByte(s)
32 case types.DateFamily:
33 return ParseDDate(ctx, s)
34 case types.DecimalFamily:
35 return ParseDDecimal(s)
36 case types.FloatFamily:
37 return ParseDFloat(s)
38 case types.INetFamily:
39 return ParseDIPAddrFromINetString(s)
40 case types.IntFamily:
41 return ParseDInt(s)
42 case types.IntervalFamily:
43 itm, err := t.IntervalTypeMetadata()
44 if err != nil {
45 return nil, err
46 }
47 return ParseDIntervalWithTypeMetadata(s, itm)
48 case types.JsonFamily:
49 return ParseDJSON(s)
50 case types.OidFamily:
51 i, err := ParseDInt(s)
52 return NewDOid(*i), err
53 case types.StringFamily:
54 // If the string type specifies a limit we truncate to that limit:
55 // 'hello'::CHAR(2) -> 'he'
56 // This is true of all the string type variants.
57 if t.Width() > 0 {
58 s = util.TruncateString(s, int(t.Width()))
59 }
60 return NewDString(s), nil
61 case types.TimeFamily:
62 return ParseDTime(ctx, s, TimeFamilyPrecisionToRoundDuration(t.Precision()))
63 case types.TimeTZFamily:
64 return ParseDTimeTZ(ctx, s, TimeFamilyPrecisionToRoundDuration(t.Precision()))
65 case types.TimestampFamily:
66 return ParseDTimestamp(ctx, s, TimeFamilyPrecisionToRoundDuration(t.Precision()))
67 case types.TimestampTZFamily:
68 return ParseDTimestampTZ(ctx, s, TimeFamilyPrecisionToRoundDuration(t.Precision()))
69 case types.UuidFamily:
70 return ParseDUuidFromString(s)
71 default:
72 return nil, errors.AssertionFailedf("unknown type %s (%T)", t, t)
73 }
74}

Callers 2

parseElementMethod · 0.85
ResolveAsTypeMethod · 0.85

Calls 15

TruncateStringFunction · 0.92
ParseDArrayFromStringFunction · 0.85
ParseDBitArrayFunction · 0.85
ParseDBoolFunction · 0.85
ParseDByteFunction · 0.85
ParseDDateFunction · 0.85
ParseDDecimalFunction · 0.85
ParseDFloatFunction · 0.85
ParseDIntFunction · 0.85
ParseDJSONFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…