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

Method Prev

pkg/sql/sem/tree/datum.go:2970–2998  ·  view source on GitHub ↗

Prev implements the Datum interface.

(ctx *EvalContext)

Source from the content-addressed store, hash-verified

2968
2969// Prev implements the Datum interface.
2970func (d *DTuple) Prev(ctx *EvalContext) (Datum, bool) {
2971 // Note: (a:decimal, b:int, c:int) has a prev value; that's (a, b,
2972 // c-1). With an exception if c is MinInt64, in which case the prev
2973 // value is (a, b-1, max(_ *EvalContext)). However, (a:int, b:decimal) does not
2974 // have a prev value, because decimal doesn't have one.
2975 //
2976 // In general, a tuple has a prev value if and only if it ends with
2977 // zero or more values that are a minimum and a maximum value of the
2978 // same type exists, and the first element before that has a prev
2979 // value.
2980 res := NewDTupleWithLen(d.typ, len(d.D))
2981 copy(res.D, d.D)
2982 for i := len(res.D) - 1; i >= 0; i-- {
2983 if !res.D[i].IsMin(ctx) {
2984 prevVal, ok := res.D[i].Prev(ctx)
2985 if !ok {
2986 return nil, false
2987 }
2988 res.D[i] = prevVal
2989 break
2990 }
2991 maxVal, ok := res.D[i].Max(ctx)
2992 if !ok {
2993 return nil, false
2994 }
2995 res.D[i] = maxVal
2996 }
2997 return res, true
2998}
2999
3000// Next implements the Datum interface.
3001func (d *DTuple) Next(ctx *EvalContext) (Datum, bool) {

Callers

nothing calls this directly

Calls 4

NewDTupleWithLenFunction · 0.85
IsMinMethod · 0.65
PrevMethod · 0.65
MaxMethod · 0.65

Tested by

no test coverage detected