MCPcopy Create free account
hub / github.com/PostHog/duckgres / encodeInterval

Function encodeInterval

server/types.go:612–623  ·  view source on GitHub ↗

encodeInterval encodes an INTERVAL value in PostgreSQL binary format: int64 microseconds + int32 days + int32 months = 16 bytes.

(v interface{})

Source from the content-addressed store, hash-verified

610// encodeInterval encodes an INTERVAL value in PostgreSQL binary format:
611// int64 microseconds + int32 days + int32 months = 16 bytes.
612func encodeInterval(v interface{}) []byte {
613 v = normalizeDriverValue(v)
614 buf := make([]byte, 16)
615 val, ok := v.(arrowmap.IntervalValue)
616 if !ok {
617 return nil
618 }
619 binary.BigEndian.PutUint64(buf[0:8], uint64(val.Micros))
620 binary.BigEndian.PutUint32(buf[8:12], uint32(val.Days))
621 binary.BigEndian.PutUint32(buf[12:16], uint32(val.Months))
622 return buf
623}
624
625// decodeInterval decodes PostgreSQL binary INTERVAL (16 bytes) into an interval string.
626func decodeInterval(data []byte) (string, error) {

Callers 2

TestEncodeDecodeIntervalFunction · 0.85
encodeBinaryFunction · 0.85

Calls 1

normalizeDriverValueFunction · 0.85

Tested by 1

TestEncodeDecodeIntervalFunction · 0.68