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

Function parseDInterval

pkg/sql/sem/tree/datum.go:2554–2592  ·  view source on GitHub ↗
(s string, itm types.IntervalTypeMetadata)

Source from the content-addressed store, hash-verified

2552}
2553
2554func parseDInterval(s string, itm types.IntervalTypeMetadata) (*DInterval, error) {
2555 // At this time the only supported interval formats are:
2556 // - SQL standard.
2557 // - Postgres compatible.
2558 // - iso8601 format (with designators only), see interval.go for
2559 // sources of documentation.
2560 // - Golang time.parseDuration compatible.
2561
2562 // If it's a blank string, exit early.
2563 if len(s) == 0 {
2564 return nil, makeParseError(s, types.Interval, nil)
2565 }
2566 if s[0] == 'P' {
2567 // If it has a leading P we're most likely working with an iso8601
2568 // interval.
2569 dur, err := iso8601ToDuration(s)
2570 if err != nil {
2571 return nil, makeParseError(s, types.Interval, err)
2572 }
2573 return &DInterval{Duration: dur}, nil
2574 }
2575 if strings.IndexFunc(s, unicode.IsLetter) == -1 {
2576 // If it has no letter, then we're most likely working with a SQL standard
2577 // interval, as both postgres and golang have letter(s) and iso8601 has been tested.
2578 dur, err := sqlStdToDuration(s, itm)
2579 if err != nil {
2580 return nil, makeParseError(s, types.Interval, err)
2581 }
2582 return &DInterval{Duration: dur}, nil
2583 }
2584
2585 // We're either a postgres string or a Go duration.
2586 // Our postgres syntax parser also supports golang, so just use that for both.
2587 dur, err := parseDuration(s, itm)
2588 if err != nil {
2589 return nil, makeParseError(s, types.Interval, err)
2590 }
2591 return &DInterval{Duration: dur}, nil
2592}
2593
2594// ResolvedType implements the TypedExpr interface.
2595func (*DInterval) ResolvedType() *types.T {

Callers 1

Calls 4

makeParseErrorFunction · 0.85
iso8601ToDurationFunction · 0.85
sqlStdToDurationFunction · 0.85
parseDurationFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…