cockroach: github.com/cockroachdb/cockroach/pkg/sql/parser Index | Files

package parser

import "github.com/cockroachdb/cockroach/pkg/sql/parser"

Code generated by goyacc. GENERATED FILE DO NOT EDIT

Index

Package Files

aggregate_builtins.go alter_table.go backup.go builtins.go col_types.go constant.go copy.go create.go datum.go decimal.go delete.go drop.go encode.go eval.go explain.go expr.go format.go function_definition.go function_name.go generator_builtins.go grant.go hide_constants.go indexed_vars.go insert.go interval.go keywords.go name_part.go normalize.go overload.go parse.go pg_builtins.go placeholders.go prepare.go regexp_cache.go rename.go reserved_keywords.go returning.go revoke.go run_control.go scan.go select.go set.go show.go split.go sql.go stmt.go table_name.go table_pattern.go table_ref.go truncate.go txn.go type.go type_check.go union.go update.go values.go var_name.go walk.go window_builtins.go

Constants

const (
    DistinctFuncType funcType
    AllFuncType
)

FuncExpr.Type

const ACTION = 57362
const ADD = 57363
const ALL = 57364
const ALTER = 57365
const ANALYSE = 57366
const ANALYZE = 57367
const AND = 57368
const ANNOTATE_TYPE = 57370
const ANY = 57369
const ARRAY = 57371
const AS = 57372
const ASC = 57373
const ASYMMETRIC = 57374
const AS_LA = 57664
const AT = 57375
const BACKUP = 57376
const BCONST = 57348
const BEGIN = 57377
const BETWEEN = 57378
const BIGINT = 57379
const BIGSERIAL = 57380
const BIT = 57381
const BLOB = 57382
const BOOL = 57383
const BOOLEAN = 57384
const BOTH = 57385
const BY = 57386
const BYTEA = 57387
const BYTES = 57388
const CANCEL = 57389
const CASCADE = 57390
const CASE = 57391
const CAST = 57392
const CHAR = 57393
const CHARACTER = 57394
const CHARACTERISTICS = 57395
const CHECK = 57396
const CLUSTER = 57397
const COALESCE = 57398
const COLLATE = 57399
const COLLATION = 57400
const COLUMN = 57401
const COLUMNS = 57402
const COMMIT = 57403
const COMMITTED = 57404
const CONCAT = 57405
const CONFLICT = 57406
const CONSTRAINT = 57407
const CONSTRAINTS = 57408
const COPY = 57409
const COVERING = 57410
const CREATE = 57411
const CROSS = 57412
const CUBE = 57413
const CURRENT = 57414
const CURRENT_CATALOG = 57415
const CURRENT_DATE = 57416
const CURRENT_ROLE = 57417
const CURRENT_TIME = 57418
const CURRENT_TIMESTAMP = 57419
const CURRENT_USER = 57420
const CYCLE = 57421
const DATA = 57422
const DATABASE = 57423
const DATABASES = 57424
const DATE = 57425
const DAY = 57426
const DEALLOCATE = 57430
const DEC = 57427
const DECIMAL = 57428
const DEFAULT = 57429
const DEFERRABLE = 57431
const DELETE = 57432
const DESC = 57433
const DISTINCT = 57434
const DO = 57435
const DOT_DOT = 57354
const DOUBLE = 57436
const DROP = 57437
const ELSE = 57438
const ENCODING = 57439
const END = 57440
const ERROR = 57361
const ESCAPE = 57441
const EXCEPT = 57442
const EXECUTE = 57444
const EXISTS = 57443
const EXPERIMENTAL_FINGERPRINTS = 57445
const EXPLAIN = 57446
const EXTRACT = 57447
const EXTRACT_DURATION = 57448
const FALSE = 57449
const FAMILY = 57450
const FCONST = 57350
const FETCH = 57451
const FILTER = 57452
const FIRST = 57453
const FLOAT = 57454
const FLOORDIV = 57455
const FOLLOWING = 57456
const FOR = 57457
const FORCE_INDEX = 57458
const FOREIGN = 57459
const FROM = 57460
const FULL = 57461
const GRANT = 57462
const GRANTS = 57463
const GREATER_EQUALS = 57356
const GREATEST = 57464
const GROUP = 57465
const GROUPING = 57466
const HAVING = 57467
const HELP = 57468
const HIGH = 57469
const HOUR = 57470
const ICONST = 57349
const IDENT = 57346
const IF = 57472
const IFNULL = 57473
const ILIKE = 57474
const IN = 57475
const INCREMENTAL = 57471
const INDEX = 57477
const INDEXES = 57478
const INITIALLY = 57479
const INNER = 57480
const INSERT = 57481
const INT = 57482
const INT2VECTOR = 57483
const INT64 = 57485
const INT8 = 57484
const INTEGER = 57486
const INTERLEAVE = 57476
const INTERSECT = 57487
const INTERVAL = 57488
const INTO = 57489
const IS = 57490
const ISOLATION = 57491
const InvalidColIdx = -1

InvalidColIdx is the index value of a non-initialized IndexedVar.

const JOB = 57492
const JOIN = 57493
const KEY = 57494
const KEYS = 57495
const KV = 57496
const LATERAL = 57497
const LC_COLLATE = 57499
const LC_CTYPE = 57498
const LEADING = 57500
const LEAST = 57501
const LEFT = 57502
const LESS_EQUALS = 57355
const LEVEL = 57503
const LIKE = 57504
const LIMIT = 57505
const LOCAL = 57506
const LOCALTIME = 57507
const LOCALTIMESTAMP = 57508
const LOW = 57509
const LSHIFT = 57510
const MATCH = 57511
const MINUTE = 57512
const MONTH = 57513
const MaxInt = int(MaxUint >> 1)

MaxInt is the maximum value of an int.

const MaxUint = ^uint(0)

MaxUint is the maximum value of an uint.

const NAME = 57515
const NAMES = 57516
const NAN = 57514
const NATURAL = 57517
const NEXT = 57518
const NO = 57519
const NORMAL = 57521
const NOT = 57522
const NOTHING = 57523
const NOT_EQUALS = 57357
const NOT_LA = 57662
const NOT_REGIMATCH = 57360
const NOT_REGMATCH = 57358
const NO_INDEX_JOIN = 57520
const NULL = 57524
const NULLIF = 57525
const NULLS = 57526
const NUMERIC = 57527
const OF = 57528
const OFF = 57529
const OFFSET = 57530
const OID = 57531
const ON = 57532
const ONLY = 57533
const OPTIONS = 57534
const OR = 57535
const ORDER = 57536
const ORDINALITY = 57537
const OUT = 57538
const OUTER = 57539
const OVER = 57540
const OVERLAPS = 57541
const OVERLAY = 57542
const PARENT = 57543
const PARTIAL = 57544
const PARTITION = 57545
const PASSWORD = 57546
const PAUSE = 57547
const PLACEHOLDER = 57351
const PLACING = 57548
const POSITION = 57549
const POSTFIXOP = 57665
const PRECEDING = 57550
const PRECISION = 57551
const PREPARE = 57552
const PRIMARY = 57553
const PRIORITY = 57554
const QUERIES = 57555
const QUERY = 57556
const RANGE = 57557
const READ = 57558
const REAL = 57559
const RECURSIVE = 57560
const REF = 57561
const REFERENCES = 57562
const REGCLASS = 57563
const REGIMATCH = 57359
const REGNAMESPACE = 57566
const REGPROC = 57564
const REGPROCEDURE = 57565
const REGTYPE = 57567
const RELEASE = 57570
const RENAME = 57568
const REPEATABLE = 57569
const RESET = 57571
const RESTORE = 57572
const RESTRICT = 57573
const RESUME = 57574
const RETURNING = 57575
const REVOKE = 57576
const RIGHT = 57577
const ROLLBACK = 57578
const ROLLUP = 57579
const ROW = 57580
const ROWS = 57581
const RSHIFT = 57582
const RestartSavepointName string = "COCKROACH_RESTART"

RestartSavepointName is the only savepoint name that we accept, modulo capitalization.

const SAVEPOINT = 57583
const SCATTER = 57584
const SCONST = 57347
const SEARCH = 57585
const SECOND = 57586
const SELECT = 57587
const SERIAL = 57588
const SERIALIZABLE = 57589
const SESSION = 57590
const SESSIONS = 57591
const SESSION_USER = 57592
const SET = 57593
const SETTING = 57594
const SETTINGS = 57595
const SHOW = 57596
const SIMILAR = 57597
const SIMPLE = 57598
const SMALLINT = 57599
const SMALLSERIAL = 57600
const SNAPSHOT = 57601
const SOME = 57602
const SPLIT = 57603
const SQL = 57604
const START = 57605
const STATUS = 57606
const STDIN = 57607
const STORING = 57610
const STRICT = 57608
const STRING = 57609
const SUBSTRING = 57611
const SYMMETRIC = 57612
const SYSTEM = 57613
const TABLE = 57614
const TABLES = 57615
const TEMPLATE = 57616
const TESTING_RANGES = 57617
const TESTING_RELOCATE = 57618
const TEXT = 57619
const THEN = 57620
const TIME = 57621
const TIMESTAMP = 57622
const TIMESTAMPTZ = 57623
const TO = 57624
const TRACE = 57626
const TRAILING = 57625
const TRANSACTION = 57627
const TREAT = 57628
const TRIM = 57629
const TRUE = 57630
const TRUNCATE = 57631
const TYPE = 57632
const TYPEANNOTATE = 57353
const TYPECAST = 57352
const (

    // TimestampOutputFormat is used to output all timestamps.
    TimestampOutputFormat = "2006-01-02 15:04:05.999999-07:00"
)

time.Time formats.

const UMINUS = 57666
const UNBOUNDED = 57633
const UNCOMMITTED = 57634
const UNION = 57635
const UNIQUE = 57636
const UNKNOWN = 57637
const UPDATE = 57638
const UPSERT = 57639
const USE = 57640
const USER = 57641
const USERS = 57642
const USING = 57643
const UUID = 57644
const VALID = 57645
const VALIDATE = 57646
const VALUE = 57647
const VALUES = 57648
const VARCHAR = 57649
const VARIADIC = 57650
const VARYING = 57652
const VIEW = 57651
const WHEN = 57653
const WHERE = 57654
const WINDOW = 57655
const WITH = 57656
const WITHIN = 57657
const WITHOUT = 57658
const WITH_LA = 57663
const WRITE = 57659
const YEAR = 57660
const ZONE = 57661

Variables

var (

    // DBoolTrue is a pointer to the DBool(true) value and can be used in
    // comparisons against Datum types.
    DBoolTrue = &constDBoolTrue
    // DBoolFalse is a pointer to the DBool(false) value and can be used in
    // comparisons against Datum types.
    DBoolFalse = &constDBoolFalse

    // DNull is the NULL Datum.
    DNull Datum = dNull{}

    // DZero is the zero-valued integer Datum.
    DZero = NewDInt(0)
)
var (
    // DecimalCtx is the default context for decimal operations. Any change
    // in the exponent limits must still guarantee a safe conversion to the
    // postegrs binary decimal format in the wire protocol, which uses an
    // int16. See pgwire/types.go.
    DecimalCtx = &apd.Context{
        Precision:   20,
        Rounding:    apd.RoundHalfUp,
        MaxExponent: 2000,
        MinExponent: -2000,
        Traps:       apd.DefaultTraps,
    }
    // ExactCtx is a decimal context with exact precision.
    ExactCtx = DecimalCtx.WithPrecision(0)
    // HighPrecisionCtx is a decimal context with high precision.
    HighPrecisionCtx = DecimalCtx.WithPrecision(2000)
    // RoundCtx is a decimal context with high precision and RoundHalfEven
    // rounding.
    RoundCtx = func() *apd.Context {
        ctx := *HighPrecisionCtx
        ctx.Rounding = apd.RoundHalfEven
        return &ctx
    }()
)
var (
    // TypeNull is the type of a DNull. Can be compared with ==.
    TypeNull Type = tNull{}
    // TypeBool is the type of a DBool. Can be compared with ==.
    TypeBool Type = tBool{}
    // TypeInt is the type of a DInt. Can be compared with ==.
    TypeInt Type = tInt{}
    // TypeFloat is the type of a DFloat. Can be compared with ==.
    TypeFloat Type = tFloat{}
    // TypeDecimal is the type of a DDecimal. Can be compared with ==.
    TypeDecimal Type = tDecimal{}
    // TypeString is the type of a DString. Can be compared with ==.
    TypeString Type = tString{}
    // TypeCollatedString is the type family of a DString. CANNOT be compared with
    // ==.
    TypeCollatedString Type = TCollatedString{}
    // TypeBytes is the type of a DBytes. Can be compared with ==.
    TypeBytes Type = tBytes{}
    // TypeDate is the type of a DDate. Can be compared with ==.
    TypeDate Type = tDate{}
    // TypeTimestamp is the type of a DTimestamp. Can be compared with ==.
    TypeTimestamp Type = tTimestamp{}
    // TypeTimestampTZ is the type of a DTimestampTZ. Can be compared with ==.
    TypeTimestampTZ Type = tTimestampTZ{}
    // TypeInterval is the type of a DInterval. Can be compared with ==.
    TypeInterval Type = tInterval{}
    // TypeUUID is the type of a DUuid. Can be compared with ==.
    TypeUUID Type = tUUID{}
    // TypeTuple is the type family of a DTuple. CANNOT be compared with ==.
    TypeTuple Type = TTuple(nil)
    // TypeTable is the type family of a DTable. CANNOT be compared with ==.
    TypeTable Type = TTable{}
    // TypePlaceholder is the type family of a placeholder. CANNOT be compared
    // with ==.
    TypePlaceholder Type = TPlaceholder{}
    // TypeStringArray is the type family of a DArray containing strings. Can be
    // compared with ==.
    TypeStringArray Type = TArray{TypeString}
    // TypeIntArray is the type family of a DArray containing ints. Can be
    // compared with ==.
    TypeIntArray Type = TArray{TypeInt}
    // TypeAnyArray is the type of a DArray with a wildcard parameterized type.
    // Can be compared with ==.
    TypeAnyArray Type = TArray{TypeAny}
    // TypeAny can be any type. Can be compared with ==.
    TypeAny Type = tAny{}

    // TypeOid is the type of an OID. Can be compared with ==.
    TypeOid = tOid{oid.T_oid}
    // TypeRegClass is the type of an regclass OID variant. Can be compared with ==.
    TypeRegClass = tOid{oid.T_regclass}
    // TypeRegNamespace is the type of an regnamespace OID variant. Can be compared with ==.
    TypeRegNamespace = tOid{oid.T_regnamespace}
    // TypeRegProc is the type of an regproc OID variant. Can be compared with ==.
    TypeRegProc = tOid{oid.T_regproc}
    // TypeRegProcedure is the type of an regprocedure OID variant. Can be compared with ==.
    TypeRegProcedure = tOid{oid.T_regprocedure}
    // TypeRegType is the type of an regtype OID variant. Can be compared with ==.
    TypeRegType = tOid{oid.T_regtype}

    // TypeName is a type-alias for TypeString with a different OID. Can be
    // compared with ==.
    TypeName = wrapTypeWithOid(TypeString, oid.T_name)
    // TypeIntVector is a type-alias for a TypeIntArray with a different OID. Can
    // be compared with ==.
    TypeIntVector = wrapTypeWithOid(TypeIntArray, oid.T_int2vector)
    // TypeNameArray is the type family of a DArray containing the Name alias type.
    // Can be compared with ==.
    TypeNameArray Type = TArray{TypeName}

    // TypesAnyNonArray contains all non-array types.
    TypesAnyNonArray = []Type{
        TypeBool,
        TypeInt,
        TypeFloat,
        TypeDecimal,
        TypeString,
        TypeBytes,
        TypeDate,
        TypeTimestamp,
        TypeTimestampTZ,
        TypeInterval,
        TypeUUID,
        TypeOid,
    }
)
var AbsentReturningClause = &NoReturningClause{}

AbsentReturningClause is a ReturningClause variant representing the absence of a RETURNING clause.

var Aggregates = map[string][]Builtin{
    "array_agg": {
        makeAggBuiltinWithReturnType(
            TypeAny,
            func(args []TypedExpr) Type {
                if len(args) == 0 {
                    return unknownReturnType
                }
                return TArray{args[0].ResolvedType()}
            },
            newArrayAggregate,
            "Aggregates the selected values into an array.",
        ),
    },

    "avg": {
        makeAggBuiltin(TypeInt, TypeDecimal, newIntAvgAggregate,
            "Calculates the average of the selected values."),
        makeAggBuiltin(TypeFloat, TypeFloat, newFloatAvgAggregate,
            "Calculates the average of the selected values."),
        makeAggBuiltin(TypeDecimal, TypeDecimal, newDecimalAvgAggregate,
            "Calculates the average of the selected values."),
    },

    "bool_and": {
        makeAggBuiltin(TypeBool, TypeBool, newBoolAndAggregate,
            "Calculates the boolean value of `AND`ing all selected values."),
    },

    "bool_or": {
        makeAggBuiltin(TypeBool, TypeBool, newBoolOrAggregate,
            "Calculates the boolean value of `OR`ing all selected values."),
    },

    "concat_agg": {

        makeAggBuiltin(TypeString, TypeString, newStringConcatAggregate,
            "Concatenates all selected values."),
        makeAggBuiltin(TypeBytes, TypeBytes, newBytesConcatAggregate,
            "Concatenates all selected values."),
    },

    "count": {
        makeAggBuiltin(TypeAny, TypeInt, newCountAggregate,
            "Calculates the number of selected elements."),
    },

    "count_rows": {
        {
            impure:        true,
            class:         AggregateClass,
            Types:         ArgTypes{},
            ReturnType:    fixedReturnType(TypeInt),
            AggregateFunc: newCountRowsAggregate,
            WindowFunc: func(params []Type, evalCtx *EvalContext) WindowFunc {
                return newAggregateWindow(newCountRowsAggregate(params, evalCtx))
            },
            Info: "Calculates the number of rows.",
        },
    },

    "max": collectBuiltins(func(t Type) Builtin {
        return makeAggBuiltin(t, t, newMaxAggregate,
            "Identifies the maximum selected value.")
    }, TypesAnyNonArray...),
    "min": collectBuiltins(func(t Type) Builtin {
        return makeAggBuiltin(t, t, newMinAggregate,
            "Identifies the minimum selected value.")
    }, TypesAnyNonArray...),

    "sum_int": {
        makeAggBuiltin(TypeInt, TypeInt, newSmallIntSumAggregate,
            "Calculates the sum of the selected values."),
    },

    "sum": {
        makeAggBuiltin(TypeInt, TypeDecimal, newIntSumAggregate,
            "Calculates the sum of the selected values."),
        makeAggBuiltin(TypeFloat, TypeFloat, newFloatSumAggregate,
            "Calculates the sum of the selected values."),
        makeAggBuiltin(TypeDecimal, TypeDecimal, newDecimalSumAggregate,
            "Calculates the sum of the selected values."),
        makeAggBuiltin(TypeInterval, TypeInterval, newIntervalSumAggregate,
            "Calculates the sum of the selected values."),
    },

    "variance": {
        makeAggBuiltin(TypeInt, TypeDecimal, newIntVarianceAggregate,
            "Calculates the variance of the selected values."),
        makeAggBuiltin(TypeDecimal, TypeDecimal, newDecimalVarianceAggregate,
            "Calculates the variance of the selected values."),
        makeAggBuiltin(TypeFloat, TypeFloat, newFloatVarianceAggregate,
            "Calculates the variance of the selected values."),
    },

    "stddev": {
        makeAggBuiltin(TypeInt, TypeDecimal, newIntStdDevAggregate,
            "Calculates the standard deviation of the selected values."),
        makeAggBuiltin(TypeDecimal, TypeDecimal, newDecimalStdDevAggregate,
            "Calculates the standard deviation of the selected values."),
        makeAggBuiltin(TypeFloat, TypeFloat, newFloatStdDevAggregate,
            "Calculates the standard deviation of the selected values."),
    },

    "xor_agg": {
        makeAggBuiltin(TypeBytes, TypeBytes, newBytesXorAggregate,
            "Calculates the bitwise XOR of the selected values."),
        makeAggBuiltin(TypeInt, TypeInt, newIntXorAggregate,
            "Calculates the bitwise XOR of the selected values."),
    },
}

Aggregates are a special class of builtin functions that are wrapped at execution in a bucketing layer to combine (aggregate) the result of the function being run over many rows. See `aggregateFuncHolder` in the sql package. In particular they must not be simplified during normalization (and thus must be marked as impure), even when they are given a constant argument (e.g. SUM(1)). This is because aggregate functions must return NULL when they are no rows in the source table, so their evaluation must always be delayed until query execution. Exported for use in documentation.

var BinOps = map[BinaryOperator]binOpOverload{
    Bitand: {
        BinOp{
            LeftType:   TypeInt,
            RightType:  TypeInt,
            ReturnType: TypeInt,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return NewDInt(MustBeDInt(left) & MustBeDInt(right)), nil
            },
        },
    },

    Bitor: {
        BinOp{
            LeftType:   TypeInt,
            RightType:  TypeInt,
            ReturnType: TypeInt,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return NewDInt(MustBeDInt(left) | MustBeDInt(right)), nil
            },
        },
    },

    Bitxor: {
        BinOp{
            LeftType:   TypeInt,
            RightType:  TypeInt,
            ReturnType: TypeInt,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return NewDInt(MustBeDInt(left) ^ MustBeDInt(right)), nil
            },
        },
    },

    Plus: {
        BinOp{
            LeftType:   TypeInt,
            RightType:  TypeInt,
            ReturnType: TypeInt,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                a, b := MustBeDInt(left), MustBeDInt(right)
                if b > 0 && a > math.MaxInt64-b {
                    return nil, errIntOutOfRange
                }
                if b < 0 && a < math.MinInt64-b {
                    return nil, errIntOutOfRange
                }
                return NewDInt(a + b), nil
            },
        },
        BinOp{
            LeftType:   TypeFloat,
            RightType:  TypeFloat,
            ReturnType: TypeFloat,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return NewDFloat(*left.(*DFloat) + *right.(*DFloat)), nil
            },
        },
        BinOp{
            LeftType:   TypeDecimal,
            RightType:  TypeDecimal,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                l := &left.(*DDecimal).Decimal
                r := &right.(*DDecimal).Decimal
                dd := &DDecimal{}
                _, err := ExactCtx.Add(&dd.Decimal, l, r)
                return dd, err
            },
        },
        BinOp{
            LeftType:   TypeDecimal,
            RightType:  TypeInt,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                l := &left.(*DDecimal).Decimal
                r := MustBeDInt(right)
                dd := &DDecimal{}
                dd.SetCoefficient(int64(r))
                _, err := ExactCtx.Add(&dd.Decimal, l, &dd.Decimal)
                return dd, err
            },
        },
        BinOp{
            LeftType:   TypeInt,
            RightType:  TypeDecimal,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                l := MustBeDInt(left)
                r := &right.(*DDecimal).Decimal
                dd := &DDecimal{}
                dd.SetCoefficient(int64(l))
                _, err := ExactCtx.Add(&dd.Decimal, &dd.Decimal, r)
                return dd, err
            },
        },
        BinOp{
            LeftType:   TypeDate,
            RightType:  TypeInt,
            ReturnType: TypeDate,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return NewDDate(*left.(*DDate) + DDate(MustBeDInt(right))), nil
            },
        },
        BinOp{
            LeftType:   TypeInt,
            RightType:  TypeDate,
            ReturnType: TypeDate,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return NewDDate(DDate(MustBeDInt(left)) + *right.(*DDate)), nil
            },
        },
        BinOp{
            LeftType:   TypeTimestamp,
            RightType:  TypeInterval,
            ReturnType: TypeTimestamp,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return MakeDTimestamp(duration.Add(left.(*DTimestamp).Time, right.(*DInterval).Duration), time.Microsecond), nil
            },
        },
        BinOp{
            LeftType:   TypeInterval,
            RightType:  TypeTimestamp,
            ReturnType: TypeTimestamp,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return MakeDTimestamp(duration.Add(right.(*DTimestamp).Time, left.(*DInterval).Duration), time.Microsecond), nil
            },
        },
        BinOp{
            LeftType:   TypeTimestampTZ,
            RightType:  TypeInterval,
            ReturnType: TypeTimestampTZ,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                t := duration.Add(left.(*DTimestampTZ).Time, right.(*DInterval).Duration)
                return MakeDTimestampTZ(t, time.Microsecond), nil
            },
        },
        BinOp{
            LeftType:   TypeInterval,
            RightType:  TypeTimestampTZ,
            ReturnType: TypeTimestampTZ,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                t := duration.Add(right.(*DTimestampTZ).Time, left.(*DInterval).Duration)
                return MakeDTimestampTZ(t, time.Microsecond), nil
            },
        },
        BinOp{
            LeftType:   TypeInterval,
            RightType:  TypeInterval,
            ReturnType: TypeInterval,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return &DInterval{Duration: left.(*DInterval).Duration.Add(right.(*DInterval).Duration)}, nil
            },
        },
        BinOp{
            LeftType:   TypeDate,
            RightType:  TypeInterval,
            ReturnType: TypeTimestampTZ,
            fn: func(ctx *EvalContext, left Datum, right Datum) (Datum, error) {
                leftTZ := MakeDTimestampTZFromDate(ctx.GetLocation(), left.(*DDate))
                t := duration.Add(leftTZ.Time, right.(*DInterval).Duration)
                return MakeDTimestampTZ(t, time.Microsecond), nil
            },
        },
        BinOp{
            LeftType:   TypeInterval,
            RightType:  TypeDate,
            ReturnType: TypeTimestampTZ,
            fn: func(ctx *EvalContext, left Datum, right Datum) (Datum, error) {
                rightTZ := MakeDTimestampTZFromDate(ctx.GetLocation(), right.(*DDate))
                t := duration.Add(rightTZ.Time, left.(*DInterval).Duration)
                return MakeDTimestampTZ(t, time.Microsecond), nil
            },
        },
    },

    Minus: {
        BinOp{
            LeftType:   TypeInt,
            RightType:  TypeInt,
            ReturnType: TypeInt,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                a, b := MustBeDInt(left), MustBeDInt(right)
                if b < 0 && a > math.MaxInt64+b {
                    return nil, errIntOutOfRange
                }
                if b > 0 && a < math.MinInt64+b {
                    return nil, errIntOutOfRange
                }
                return NewDInt(a - b), nil
            },
        },
        BinOp{
            LeftType:   TypeFloat,
            RightType:  TypeFloat,
            ReturnType: TypeFloat,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return NewDFloat(*left.(*DFloat) - *right.(*DFloat)), nil
            },
        },
        BinOp{
            LeftType:   TypeDecimal,
            RightType:  TypeDecimal,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                l := &left.(*DDecimal).Decimal
                r := &right.(*DDecimal).Decimal
                dd := &DDecimal{}
                _, err := ExactCtx.Sub(&dd.Decimal, l, r)
                return dd, err
            },
        },
        BinOp{
            LeftType:   TypeDecimal,
            RightType:  TypeInt,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                l := &left.(*DDecimal).Decimal
                r := MustBeDInt(right)
                dd := &DDecimal{}
                dd.SetCoefficient(int64(r))
                _, err := ExactCtx.Sub(&dd.Decimal, l, &dd.Decimal)
                return dd, err
            },
        },
        BinOp{
            LeftType:   TypeInt,
            RightType:  TypeDecimal,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                l := MustBeDInt(left)
                r := &right.(*DDecimal).Decimal
                dd := &DDecimal{}
                dd.SetCoefficient(int64(l))
                _, err := ExactCtx.Sub(&dd.Decimal, &dd.Decimal, r)
                return dd, err
            },
        },
        BinOp{
            LeftType:   TypeDate,
            RightType:  TypeInt,
            ReturnType: TypeDate,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return NewDDate(*left.(*DDate) - DDate(MustBeDInt(right))), nil
            },
        },
        BinOp{
            LeftType:   TypeDate,
            RightType:  TypeDate,
            ReturnType: TypeInt,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return NewDInt(DInt(*left.(*DDate) - *right.(*DDate))), nil
            },
        },
        BinOp{
            LeftType:   TypeTimestamp,
            RightType:  TypeTimestamp,
            ReturnType: TypeInterval,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                nanos := left.(*DTimestamp).Sub(right.(*DTimestamp).Time).Nanoseconds()
                return &DInterval{Duration: duration.Duration{Nanos: nanos}}, nil
            },
        },
        BinOp{
            LeftType:   TypeTimestampTZ,
            RightType:  TypeTimestampTZ,
            ReturnType: TypeInterval,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                nanos := left.(*DTimestampTZ).Sub(right.(*DTimestampTZ).Time).Nanoseconds()
                return &DInterval{Duration: duration.Duration{Nanos: nanos}}, nil
            },
        },
        BinOp{
            LeftType:   TypeTimestamp,
            RightType:  TypeTimestampTZ,
            ReturnType: TypeInterval,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                nanos := left.(*DTimestamp).Sub(right.(*DTimestampTZ).Time).Nanoseconds()
                return &DInterval{Duration: duration.Duration{Nanos: nanos}}, nil
            },
        },
        BinOp{
            LeftType:   TypeTimestampTZ,
            RightType:  TypeTimestamp,
            ReturnType: TypeInterval,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                nanos := left.(*DTimestampTZ).Sub(right.(*DTimestamp).Time).Nanoseconds()
                return &DInterval{Duration: duration.Duration{Nanos: nanos}}, nil
            },
        },
        BinOp{
            LeftType:   TypeTimestamp,
            RightType:  TypeInterval,
            ReturnType: TypeTimestamp,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return MakeDTimestamp(duration.Add(left.(*DTimestamp).Time, right.(*DInterval).Duration.Mul(-1)), time.Microsecond), nil
            },
        },
        BinOp{
            LeftType:   TypeTimestampTZ,
            RightType:  TypeInterval,
            ReturnType: TypeTimestampTZ,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                t := duration.Add(left.(*DTimestampTZ).Time, right.(*DInterval).Duration.Mul(-1))
                return MakeDTimestampTZ(t, time.Microsecond), nil
            },
        },
        BinOp{
            LeftType:   TypeDate,
            RightType:  TypeInterval,
            ReturnType: TypeTimestampTZ,
            fn: func(ctx *EvalContext, left Datum, right Datum) (Datum, error) {
                leftTZ := MakeDTimestampTZFromDate(ctx.GetLocation(), left.(*DDate))
                t := duration.Add(leftTZ.Time, right.(*DInterval).Duration.Mul(-1))
                return MakeDTimestampTZ(t, time.Microsecond), nil
            },
        },
        BinOp{
            LeftType:   TypeInterval,
            RightType:  TypeInterval,
            ReturnType: TypeInterval,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return &DInterval{Duration: left.(*DInterval).Duration.Sub(right.(*DInterval).Duration)}, nil
            },
        },
    },

    Mult: {
        BinOp{
            LeftType:   TypeInt,
            RightType:  TypeInt,
            ReturnType: TypeInt,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {

                a, b := MustBeDInt(left), MustBeDInt(right)
                c := a * b
                if a == 0 || b == 0 || a == 1 || b == 1 {

                } else if a == math.MinInt64 || b == math.MinInt64 {

                    return nil, errIntOutOfRange
                } else if c/b != a {
                    return nil, errIntOutOfRange
                }
                return NewDInt(c), nil
            },
        },
        BinOp{
            LeftType:   TypeFloat,
            RightType:  TypeFloat,
            ReturnType: TypeFloat,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return NewDFloat(*left.(*DFloat) * *right.(*DFloat)), nil
            },
        },
        BinOp{
            LeftType:   TypeDecimal,
            RightType:  TypeDecimal,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                l := &left.(*DDecimal).Decimal
                r := &right.(*DDecimal).Decimal
                dd := &DDecimal{}
                _, err := ExactCtx.Mul(&dd.Decimal, l, r)
                return dd, err
            },
        },

        BinOp{
            LeftType:   TypeDecimal,
            RightType:  TypeInt,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                l := &left.(*DDecimal).Decimal
                r := MustBeDInt(right)
                dd := &DDecimal{}
                dd.SetCoefficient(int64(r))
                _, err := ExactCtx.Mul(&dd.Decimal, l, &dd.Decimal)
                return dd, err
            },
        },
        BinOp{
            LeftType:   TypeInt,
            RightType:  TypeDecimal,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                l := MustBeDInt(left)
                r := &right.(*DDecimal).Decimal
                dd := &DDecimal{}
                dd.SetCoefficient(int64(l))
                _, err := ExactCtx.Mul(&dd.Decimal, &dd.Decimal, r)
                return dd, err
            },
        },
        BinOp{
            LeftType:   TypeInt,
            RightType:  TypeInterval,
            ReturnType: TypeInterval,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return &DInterval{Duration: right.(*DInterval).Duration.Mul(int64(MustBeDInt(left)))}, nil
            },
        },
        BinOp{
            LeftType:   TypeInterval,
            RightType:  TypeInt,
            ReturnType: TypeInterval,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return &DInterval{Duration: left.(*DInterval).Duration.Mul(int64(MustBeDInt(right)))}, nil
            },
        },
        BinOp{
            LeftType:   TypeInterval,
            RightType:  TypeFloat,
            ReturnType: TypeInterval,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                r := float64(*right.(*DFloat))
                return &DInterval{Duration: left.(*DInterval).Duration.MulFloat(r)}, nil
            },
        },
    },

    Div: {
        BinOp{
            LeftType:   TypeInt,
            RightType:  TypeInt,
            ReturnType: TypeDecimal,
            fn: func(ctx *EvalContext, left Datum, right Datum) (Datum, error) {
                rInt := MustBeDInt(right)
                div := ctx.getTmpDec().SetCoefficient(int64(rInt)).SetExponent(0)
                dd := &DDecimal{}
                dd.SetCoefficient(int64(MustBeDInt(left)))
                _, err := DecimalCtx.Quo(&dd.Decimal, &dd.Decimal, div)
                return dd, err
            },
        },
        BinOp{
            LeftType:   TypeFloat,
            RightType:  TypeFloat,
            ReturnType: TypeFloat,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return NewDFloat(*left.(*DFloat) / *right.(*DFloat)), nil
            },
        },
        BinOp{
            LeftType:   TypeDecimal,
            RightType:  TypeDecimal,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                l := &left.(*DDecimal).Decimal
                r := &right.(*DDecimal).Decimal
                dd := &DDecimal{}
                _, err := DecimalCtx.Quo(&dd.Decimal, l, r)
                return dd, err
            },
        },
        BinOp{
            LeftType:   TypeDecimal,
            RightType:  TypeInt,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                l := &left.(*DDecimal).Decimal
                r := MustBeDInt(right)
                dd := &DDecimal{}
                dd.SetCoefficient(int64(r))
                _, err := DecimalCtx.Quo(&dd.Decimal, l, &dd.Decimal)
                return dd, err
            },
        },
        BinOp{
            LeftType:   TypeInt,
            RightType:  TypeDecimal,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                l := MustBeDInt(left)
                r := &right.(*DDecimal).Decimal
                dd := &DDecimal{}
                dd.SetCoefficient(int64(l))
                _, err := DecimalCtx.Quo(&dd.Decimal, &dd.Decimal, r)
                return dd, err
            },
        },
        BinOp{
            LeftType:   TypeInterval,
            RightType:  TypeInt,
            ReturnType: TypeInterval,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                rInt := MustBeDInt(right)
                if rInt == 0 {
                    return nil, errDivByZero
                }
                return &DInterval{Duration: left.(*DInterval).Duration.Div(int64(rInt))}, nil
            },
        },
        BinOp{
            LeftType:   TypeInterval,
            RightType:  TypeFloat,
            ReturnType: TypeInterval,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                r := float64(*right.(*DFloat))
                if r == 0.0 {
                    return nil, errDivByZero
                }
                return &DInterval{Duration: left.(*DInterval).Duration.DivFloat(r)}, nil
            },
        },
    },

    FloorDiv: {
        BinOp{
            LeftType:   TypeInt,
            RightType:  TypeInt,
            ReturnType: TypeInt,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                rInt := MustBeDInt(right)
                if rInt == 0 {
                    return nil, errDivByZero
                }
                return NewDInt(MustBeDInt(left) / rInt), nil
            },
        },
        BinOp{
            LeftType:   TypeFloat,
            RightType:  TypeFloat,
            ReturnType: TypeFloat,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                l := float64(*left.(*DFloat))
                r := float64(*right.(*DFloat))
                return NewDFloat(DFloat(math.Trunc(l / r))), nil
            },
        },
        BinOp{
            LeftType:   TypeDecimal,
            RightType:  TypeDecimal,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                l := &left.(*DDecimal).Decimal
                r := &right.(*DDecimal).Decimal
                dd := &DDecimal{}
                _, err := HighPrecisionCtx.QuoInteger(&dd.Decimal, l, r)
                return dd, err
            },
        },
        BinOp{
            LeftType:   TypeDecimal,
            RightType:  TypeInt,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                l := &left.(*DDecimal).Decimal
                r := MustBeDInt(right)
                if r == 0 {
                    return nil, errDivByZero
                }
                dd := &DDecimal{}
                dd.SetCoefficient(int64(r))
                _, err := HighPrecisionCtx.QuoInteger(&dd.Decimal, l, &dd.Decimal)
                return dd, err
            },
        },
        BinOp{
            LeftType:   TypeInt,
            RightType:  TypeDecimal,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                l := MustBeDInt(left)
                r := &right.(*DDecimal).Decimal
                if r.Sign() == 0 {
                    return nil, errDivByZero
                }
                dd := &DDecimal{}
                dd.SetCoefficient(int64(l))
                _, err := HighPrecisionCtx.QuoInteger(&dd.Decimal, &dd.Decimal, r)
                return dd, err
            },
        },
    },

    Mod: {
        BinOp{
            LeftType:   TypeInt,
            RightType:  TypeInt,
            ReturnType: TypeInt,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                r := MustBeDInt(right)
                if r == 0 {
                    return nil, errZeroModulus
                }
                return NewDInt(MustBeDInt(left) % r), nil
            },
        },
        BinOp{
            LeftType:   TypeFloat,
            RightType:  TypeFloat,
            ReturnType: TypeFloat,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return NewDFloat(DFloat(math.Mod(float64(*left.(*DFloat)), float64(*right.(*DFloat))))), nil
            },
        },
        BinOp{
            LeftType:   TypeDecimal,
            RightType:  TypeDecimal,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                l := &left.(*DDecimal).Decimal
                r := &right.(*DDecimal).Decimal
                dd := &DDecimal{}
                _, err := HighPrecisionCtx.Rem(&dd.Decimal, l, r)
                return dd, err
            },
        },
        BinOp{
            LeftType:   TypeDecimal,
            RightType:  TypeInt,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                l := &left.(*DDecimal).Decimal
                r := MustBeDInt(right)
                dd := &DDecimal{}
                dd.SetCoefficient(int64(r))
                _, err := HighPrecisionCtx.Rem(&dd.Decimal, l, &dd.Decimal)
                return dd, err
            },
        },
        BinOp{
            LeftType:   TypeInt,
            RightType:  TypeDecimal,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                l := MustBeDInt(left)
                r := &right.(*DDecimal).Decimal
                dd := &DDecimal{}
                dd.SetCoefficient(int64(l))
                _, err := HighPrecisionCtx.Rem(&dd.Decimal, &dd.Decimal, r)
                return dd, err
            },
        },
    },

    Concat: {
        BinOp{
            LeftType:   TypeString,
            RightType:  TypeString,
            ReturnType: TypeString,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return NewDString(string(MustBeDString(left) + MustBeDString(right))), nil
            },
        },
        BinOp{
            LeftType:   TypeBytes,
            RightType:  TypeBytes,
            ReturnType: TypeBytes,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return NewDBytes(*left.(*DBytes) + *right.(*DBytes)), nil
            },
        },
    },

    LShift: {
        BinOp{
            LeftType:   TypeInt,
            RightType:  TypeInt,
            ReturnType: TypeInt,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return NewDInt(MustBeDInt(left) << uint(MustBeDInt(right))), nil
            },
        },
    },

    RShift: {
        BinOp{
            LeftType:   TypeInt,
            RightType:  TypeInt,
            ReturnType: TypeInt,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                return NewDInt(MustBeDInt(left) >> uint(MustBeDInt(right))), nil
            },
        },
    },

    Pow: {
        BinOp{
            LeftType:   TypeInt,
            RightType:  TypeInt,
            ReturnType: TypeInt,
            fn: func(ctx *EvalContext, left Datum, right Datum) (Datum, error) {
                return intPow(MustBeDInt(left), MustBeDInt(right))
            },
        },
        BinOp{
            LeftType:   TypeFloat,
            RightType:  TypeFloat,
            ReturnType: TypeFloat,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                f := math.Pow(float64(*left.(*DFloat)), float64(*right.(*DFloat)))
                return NewDFloat(DFloat(f)), nil
            },
        },
        BinOp{
            LeftType:   TypeDecimal,
            RightType:  TypeDecimal,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                l := &left.(*DDecimal).Decimal
                r := &right.(*DDecimal).Decimal
                dd := &DDecimal{}
                _, err := DecimalCtx.Pow(&dd.Decimal, l, r)
                return dd, err
            },
        },
        BinOp{
            LeftType:   TypeDecimal,
            RightType:  TypeInt,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                l := &left.(*DDecimal).Decimal
                r := MustBeDInt(right)
                dd := &DDecimal{}
                dd.SetCoefficient(int64(r))
                _, err := DecimalCtx.Pow(&dd.Decimal, l, &dd.Decimal)
                return dd, err
            },
        },
        BinOp{
            LeftType:   TypeInt,
            RightType:  TypeDecimal,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
                l := MustBeDInt(left)
                r := &right.(*DDecimal).Decimal
                dd := &DDecimal{}
                dd.SetCoefficient(int64(l))
                _, err := DecimalCtx.Pow(&dd.Decimal, &dd.Decimal, r)
                return dd, err
            },
        },
    },
}

BinOps contains the binary operations indexed by operation type.

var Builtins = map[string][]Builtin{

    "length": {
        stringBuiltin1(func(_ *EvalContext, s string) (Datum, error) {
            return NewDInt(DInt(utf8.RuneCountInString(s))), nil
        }, TypeInt, "Calculates the number of characters in `val`."),
        bytesBuiltin1(func(_ *EvalContext, s string) (Datum, error) {
            return NewDInt(DInt(len(s))), nil
        }, TypeInt, "Calculates the number of bytes in `val`."),
    },

    "octet_length": {
        stringBuiltin1(func(_ *EvalContext, s string) (Datum, error) {
            return NewDInt(DInt(len(s))), nil
        }, TypeInt, "Calculates the number of bytes used to represent `val`."),
        bytesBuiltin1(func(_ *EvalContext, s string) (Datum, error) {
            return NewDInt(DInt(len(s))), nil
        }, TypeInt, "Calculates the number of bytes in `val`."),
    },

    "lower": {stringBuiltin1(func(evalCtx *EvalContext, s string) (Datum, error) {
        if err := evalCtx.ActiveMemAcc.Grow(evalCtx.Ctx(), int64(len(s))); err != nil {
            return nil, err
        }
        return NewDString(strings.ToLower(s)), nil
    }, TypeString, "Converts all characters in `val`to their lower-case equivalents.")},

    "upper": {stringBuiltin1(func(evalCtx *EvalContext, s string) (Datum, error) {
        if err := evalCtx.ActiveMemAcc.Grow(evalCtx.Ctx(), int64(len(s))); err != nil {
            return nil, err
        }
        return NewDString(strings.ToUpper(s)), nil
    }, TypeString, "Converts all characters in `val`to their to their upper-case equivalents.")},

    "substr":    substringImpls,
    "substring": substringImpls,

    "concat": {
        Builtin{
            Types:      VariadicType{TypeString},
            ReturnType: fixedReturnType(TypeString),
            fn: func(evalCtx *EvalContext, args Datums) (Datum, error) {
                var buffer bytes.Buffer
                for _, d := range args {
                    if d == DNull {
                        continue
                    }
                    nextLength := len(string(MustBeDString(d)))
                    if err := evalCtx.ActiveMemAcc.Grow(evalCtx.Ctx(), int64(nextLength)); err != nil {
                        return nil, err
                    }
                    buffer.WriteString(string(MustBeDString(d)))
                }
                return NewDString(buffer.String()), nil
            },
            Info: "Concatenates a comma-separated list of strings.",
        },
    },

    "concat_ws": {
        Builtin{
            Types:      VariadicType{TypeString},
            ReturnType: fixedReturnType(TypeString),
            fn: func(evalCtx *EvalContext, args Datums) (Datum, error) {
                if len(args) == 0 {
                    return nil, errInsufficientArgs
                }
                if args[0] == DNull {
                    return DNull, nil
                }
                sep := string(MustBeDString(args[0]))
                var buf bytes.Buffer
                prefix := ""
                for _, d := range args[1:] {
                    if d == DNull {
                        continue
                    }
                    nextLength := len(prefix) + len(string(MustBeDString(d)))
                    if err := evalCtx.ActiveMemAcc.Grow(
                        evalCtx.Ctx(), int64(nextLength)); err != nil {
                        return nil, err
                    }

                    buf.WriteString(prefix)
                    prefix = sep
                    buf.WriteString(string(MustBeDString(d)))
                }
                return NewDString(buf.String()), nil
            },
            Info: "Uses the first argument as a separator between the concatenation of the " +
                "subsequent arguments. <br/><br/>For example `concat_ws('!','wow','great')` " +
                "returns `wow!great`.",
        },
    },

    "to_uuid": {
        Builtin{
            Types:      ArgTypes{{"val", TypeString}},
            ReturnType: fixedReturnType(TypeBytes),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                s := string(MustBeDString(args[0]))
                uv, err := uuid.FromString(s)
                if err != nil {
                    return nil, err
                }
                return NewDBytes(DBytes(uv.GetBytes())), nil
            },
            Info: "Converts the character string representation of a UUID to its byte string " +
                "representation.",
        },
    },

    "from_uuid": {
        Builtin{
            Types:      ArgTypes{{"val", TypeBytes}},
            ReturnType: fixedReturnType(TypeString),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                b := []byte(*args[0].(*DBytes))
                uv, err := uuid.FromBytes(b)
                if err != nil {
                    return nil, err
                }
                return NewDString(uv.String()), nil
            },
            Info: "Converts the byte string representation of a UUID to its character string " +
                "representation.",
        },
    },

    "from_ip": {
        Builtin{
            Types:      ArgTypes{{"val", TypeBytes}},
            ReturnType: fixedReturnType(TypeString),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                ipstr := args[0].(*DBytes)
                nboip := net.IP(*ipstr)
                sv := nboip.String()

                if sv == "<nil>" {
                    return nil, errZeroIP
                }
                return NewDString(sv), nil
            },
            Info: "Converts the byte string representation of an IP to its character string " +
                "representation.",
        },
    },

    "to_ip": {
        Builtin{
            Types:      ArgTypes{{"val", TypeString}},
            ReturnType: fixedReturnType(TypeBytes),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                ipdstr := MustBeDString(args[0])
                ip := net.ParseIP(string(ipdstr))

                if ip == nil {
                    return nil, fmt.Errorf("invalid IP format: %s", ipdstr.String())
                }
                return NewDBytes(DBytes(ip)), nil
            },
            Info: "Converts the character string representation of an IP to its byte string " +
                "representation.",
        },
    },

    "split_part": {
        Builtin{
            Types: ArgTypes{
                {"input", TypeString},
                {"delimiter", TypeString},
                {"return_index_pos", TypeInt},
            },
            ReturnType: fixedReturnType(TypeString),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                text := string(MustBeDString(args[0]))
                sep := string(MustBeDString(args[1]))
                field := int(MustBeDInt(args[2]))

                if field <= 0 {
                    return nil, fmt.Errorf("field position %d must be greater than zero", field)
                }

                splits := strings.Split(text, sep)
                if field > len(splits) {
                    return NewDString(""), nil
                }
                return NewDString(splits[field-1]), nil
            },
            Info: "Splits `input` on `delimiter` and return the value in the `return_index_pos`  " +
                "position (starting at 1). <br/><br/>For example, `split_part('123.456.789.0','.',3)`" +
                "returns `789`.",
        },
    },

    "repeat": {
        Builtin{
            Types:            ArgTypes{{"input", TypeString}, {"repeat_counter", TypeInt}},
            distsqlBlacklist: true,
            ReturnType:       fixedReturnType(TypeString),
            fn: func(evalCtx *EvalContext, args Datums) (_ Datum, err error) {
                s := string(MustBeDString(args[0]))
                count := int(MustBeDInt(args[1]))

                if count < 0 {
                    count = 0
                }

                if err := evalCtx.ActiveMemAcc.Grow(evalCtx.Ctx(), int64(len(s)*count)); err != nil {
                    return nil, err
                }
                return NewDString(strings.Repeat(s, count)), nil
            },
            Info: "Concatenates `input` `repeat_counter` number of times.<br/><br/>For example, " +
                "`repeat('dog', 2)` returns `dogdog`.",
        },
    },

    "ascii": {stringBuiltin1(func(_ *EvalContext, s string) (Datum, error) {
        for _, ch := range s {
            return NewDInt(DInt(ch)), nil
        }
        return nil, errEmptyInputString
    }, TypeInt, "Calculates the ASCII value for the first character in `val`.")},

    "md5": hashBuiltin(
        func() hash.Hash { return md5.New() },
        "Calculates the MD5 hash value of a set of values.",
    ),

    "sha1": hashBuiltin(
        func() hash.Hash { return sha1.New() },
        "Calculates the SHA1 hash value of a set of values.",
    ),

    "sha256": hashBuiltin(
        func() hash.Hash { return sha256.New() },
        "Calculates the SHA256 hash value of a set of values.",
    ),

    "sha512": hashBuiltin(
        func() hash.Hash { return sha512.New() },
        "Calculates the SHA512 hash value of a set of values.",
    ),

    "fnv32": hash32Builtin(
        func() hash.Hash32 { return fnv.New32() },
        "Calculates the 32-bit FNV-1 hash value of a set of values.",
    ),

    "fnv32a": hash32Builtin(
        func() hash.Hash32 { return fnv.New32a() },
        "Calculates the 32-bit FNV-1a hash value of a set of values.",
    ),

    "fnv64": hash64Builtin(
        func() hash.Hash64 { return fnv.New64() },
        "Calculates the 64-bit FNV-1 hash value of a set of values.",
    ),

    "fnv64a": hash64Builtin(
        func() hash.Hash64 { return fnv.New64a() },
        "Calculates the 64-bit FNV-1a hash value of a set of values.",
    ),

    "crc32ieee": hash32Builtin(
        func() hash.Hash32 { return crc32.New(crc32.IEEETable) },
        "Calculates the CRC-32 hash using the IEEE polynomial.",
    ),

    "crc32c": hash32Builtin(
        func() hash.Hash32 { return crc32.New(crc32.MakeTable(crc32.Castagnoli)) },
        "Calculates the CRC-32 hash using the Castagnoli polynomial.",
    ),

    "to_hex": {
        Builtin{
            Types:      ArgTypes{{"val", TypeInt}},
            ReturnType: fixedReturnType(TypeString),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                return NewDString(fmt.Sprintf("%x", int64(MustBeDInt(args[0])))), nil
            },
            Info: "Converts `val` to its hexadecimal representation.",
        },
        Builtin{
            Types:      ArgTypes{{"val", TypeBytes}},
            ReturnType: fixedReturnType(TypeString),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                bytes := *(args[0].(*DBytes))
                return NewDString(fmt.Sprintf("%x", []byte(bytes))), nil
            },
            Info: "Converts `val` to its hexadecimal representation.",
        },
    },

    "strpos": {stringBuiltin2("input", "find", func(_ *EvalContext, s, substring string) (Datum, error) {
        index := strings.Index(s, substring)
        if index < 0 {
            return DZero, nil
        }

        return NewDInt(DInt(utf8.RuneCountInString(s[:index]) + 1)), nil
    }, TypeInt, "Calculates the position where the string `find` begins in `input`. <br/><br/>For"+
        " example, `strpos('doggie', 'gie')` returns `4`.")},

    "overlay": {
        Builtin{
            Types: ArgTypes{
                {"input", TypeString},
                {"overlay_val", TypeString},
                {"start_pos", TypeInt},
            },
            ReturnType: fixedReturnType(TypeString),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                s := string(MustBeDString(args[0]))
                to := string(MustBeDString(args[1]))
                pos := int(MustBeDInt(args[2]))
                size := utf8.RuneCountInString(to)
                return overlay(s, to, pos, size)
            },
            Info: "Replaces characters in `input` with `overlay_val` starting at `start_pos` " +
                "(begins at 1). <br/><br/>For example, `overlay('doggie', 'CAT', 2)` returns " +
                "`dCATie`.",
        },
        Builtin{
            Types: ArgTypes{
                {"input", TypeString},
                {"overlay_val", TypeString},
                {"start_pos", TypeInt},
                {"end_pos", TypeInt},
            },
            ReturnType: fixedReturnType(TypeString),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                s := string(MustBeDString(args[0]))
                to := string(MustBeDString(args[1]))
                pos := int(MustBeDInt(args[2]))
                size := int(MustBeDInt(args[3]))
                return overlay(s, to, pos, size)
            },
            Info: "Deletes the characters in `input` between `start_pos` and `end_pos` (count " +
                "starts at 1), and then insert `overlay_val` at `start_pos`.",
        },
    },

    "btrim": {
        stringBuiltin2("input", "trim_chars", func(_ *EvalContext, s, chars string) (Datum, error) {
            return NewDString(strings.Trim(s, chars)), nil
        }, TypeString, "Removes any characters included in `trim_chars` from the beginning or end"+
            " of `input` (applies recursively). <br/><br/>For example, `btrim('doggie', 'eod')` "+
            "returns `ggi`."),
        stringBuiltin1(func(_ *EvalContext, s string) (Datum, error) {
            return NewDString(strings.TrimSpace(s)), nil
        }, TypeString, "Removes all spaces from the beginning and end of `val`."),
    },

    "ltrim": {
        stringBuiltin2("input", "trim_chars", func(_ *EvalContext, s, chars string) (Datum, error) {
            return NewDString(strings.TrimLeft(s, chars)), nil
        }, TypeString, "Removes any characters included in `trim_chars` from the beginning "+
            "(left-hand side) of `input` (applies recursively). <br/><br/>For example, "+
            "`ltrim('doggie', 'od')` returns `ggie`."),
        stringBuiltin1(func(_ *EvalContext, s string) (Datum, error) {
            return NewDString(strings.TrimLeftFunc(s, unicode.IsSpace)), nil
        }, TypeString, "Removes all spaces from the beginning (left-hand side) of `val`."),
    },

    "rtrim": {
        stringBuiltin2("input", "trim_chars", func(_ *EvalContext, s, chars string) (Datum, error) {
            return NewDString(strings.TrimRight(s, chars)), nil
        }, TypeString, "Removes any characters included in `trim_chars` from the end (right-hand "+
            "side) of `input` (applies recursively). <br/><br/>For example, `rtrim('doggie', 'ei')` "+
            "returns `dogg`."),
        stringBuiltin1(func(_ *EvalContext, s string) (Datum, error) {
            return NewDString(strings.TrimRightFunc(s, unicode.IsSpace)), nil
        }, TypeString, "Removes all spaces from the end (right-hand side) of `val`."),
    },

    "reverse": {stringBuiltin1(func(evalCtx *EvalContext, s string) (Datum, error) {
        if err := evalCtx.ActiveMemAcc.Grow(evalCtx.Ctx(), int64(len(s))); err != nil {
            return nil, err
        }
        runes := []rune(s)
        for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
            runes[i], runes[j] = runes[j], runes[i]
        }
        return NewDString(string(runes)), nil
    }, TypeString, "Reverses the order of the string's characters.")},

    "replace": {stringBuiltin3(
        "input", "find", "replace",
        func(evalCtx *EvalContext, input, from, to string) (Datum, error) {
            result := strings.Replace(input, from, to, -1)
            if err := evalCtx.ActiveMemAcc.Grow(evalCtx.Ctx(), int64(len(result))); err != nil {
                return nil, err
            }
            return NewDString(result), nil
        },
        TypeString,
        "Replaces all occurrences of `find` with `replace` in `input`",
    )},

    "translate": {stringBuiltin3(
        "input", "find", "replace",
        func(evalCtx *EvalContext, s, from, to string) (Datum, error) {
            if err := evalCtx.ActiveMemAcc.Grow(evalCtx.Ctx(), int64(len(s))); err != nil {
                return nil, err
            }
            const deletionRune = utf8.MaxRune + 1
            translation := make(map[rune]rune, len(from))
            for _, fromRune := range from {
                toRune, size := utf8.DecodeRuneInString(to)
                if toRune == utf8.RuneError {
                    toRune = deletionRune
                } else {
                    to = to[size:]
                }
                translation[fromRune] = toRune
            }

            runes := make([]rune, 0, len(s))
            for _, c := range s {
                if t, ok := translation[c]; ok {
                    if t != deletionRune {
                        runes = append(runes, t)
                    }
                } else {
                    runes = append(runes, c)
                }
            }
            return NewDString(string(runes)), nil
        }, TypeString, "In `input`, replaces the first character from `find` with the first "+
            "character in `replace`; repeat for each character in `find`. <br/><br/>For example, "+
            "`translate('doggie', 'dog', '123');` returns `1233ie`.")},

    "regexp_extract": {
        Builtin{
            Types:      ArgTypes{{"input", TypeString}, {"regex", TypeString}},
            ReturnType: fixedReturnType(TypeString),
            fn: func(ctx *EvalContext, args Datums) (Datum, error) {
                s := string(MustBeDString(args[0]))
                pattern := string(MustBeDString(args[1]))
                return regexpExtract(ctx, s, pattern, `\`)
            },
            Info: "Returns the first match for the Regular Expression `regex` in `input`.",
        },
    },

    "regexp_replace": {
        Builtin{
            Types: ArgTypes{
                {"input", TypeString},
                {"regex", TypeString},
                {"replace", TypeString},
            },
            ReturnType: fixedReturnType(TypeString),
            fn: func(evalCtx *EvalContext, args Datums) (Datum, error) {
                s := string(MustBeDString(args[0]))
                pattern := string(MustBeDString(args[1]))
                to := string(MustBeDString(args[2]))
                result, err := regexpReplace(evalCtx, s, pattern, to, "")
                if err != nil {
                    return nil, err
                }
                if err := evalCtx.ActiveMemAcc.Grow(evalCtx.Ctx(), int64(len(string(MustBeDString(result))))); err != nil {
                    return nil, err
                }
                return result, nil
            },
            Info: "Replaces matches for the Regular Expression `regex` in `input` with the " +
                "Regular Expression `replace`.",
        },
        Builtin{
            Types: ArgTypes{
                {"input", TypeString},
                {"regex", TypeString},
                {"replace", TypeString},
                {"flags", TypeString},
            },
            ReturnType: fixedReturnType(TypeString),
            fn: func(evalCtx *EvalContext, args Datums) (Datum, error) {
                s := string(MustBeDString(args[0]))
                pattern := string(MustBeDString(args[1]))
                to := string(MustBeDString(args[2]))
                sqlFlags := string(MustBeDString(args[3]))
                result, err := regexpReplace(evalCtx, s, pattern, to, sqlFlags)
                if err != nil {
                    return nil, err
                }
                if err := evalCtx.ActiveMemAcc.Grow(evalCtx.Ctx(), int64(len(string(MustBeDString(result))))); err != nil {
                    return nil, err
                }
                return result, nil
            },
            Info: "Replaces matches for the Regular Expression `regex` in `input` with the Regular " +
                "Expression `replace` using `flags`.<br/><br/>CockroachDB supports the following " +
                "flags:<br/><br/>&#8226; **c**: Case-sensitive matching<br/><br/>&#8226; **g**: " +
                "Global matching (match each substring instead of only the first).<br/><br/>&#8226; " +
                "**i**: Case-insensitive matching<br/><br/>&#8226; **m** or **n**: Newline-sensitive " +
                "`.` and negated brackets (`[^...]`) do not match newline characters (preventing " +
                "matching: matches from crossing newlines unless explicitly defined to); `^` and " +
                "`$` match the space before and after newline characters respectively (so characters " +
                "between newline characters are treated as if they're on a separate line).<br/>" +
                "<br/>&#8226; **p**: Partial newline-sensitive matching: `.` and negated brackets " +
                "(`[^...]`) do not match newline characters (preventing matches from crossing " +
                "newlines unless explicitly defined to), but `^` and `$` still only match the " +
                "beginning and end of `val`.<br/><br/>&#8226; **s**: Newline-insensitive " +
                "matching *(default)*.<br/><br/>&#8226; **w**: Inverse partial newline-sensitive " +
                "matching:`.` and negated brackets (`[^...]`) *do* match newline characters, but  `^` " +
                "and `$` match the space before and after newline characters respectively (so " +
                "characters between newline characters are treated as if they're on a separate line).",
        },
    },

    "initcap": {stringBuiltin1(func(evalCtx *EvalContext, s string) (Datum, error) {
        if err := evalCtx.ActiveMemAcc.Grow(evalCtx.Ctx(), int64(len(s))); err != nil {
            return nil, err
        }
        return NewDString(strings.Title(strings.ToLower(s))), nil
    }, TypeString, "Capitalizes the first letter of `val`.")},

    "left": {
        Builtin{
            Types:      ArgTypes{{"input", TypeBytes}, {"return_set", TypeInt}},
            ReturnType: fixedReturnType(TypeBytes),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                bytes := []byte(*args[0].(*DBytes))
                n := int(MustBeDInt(args[1]))

                if n < -len(bytes) {
                    n = 0
                } else if n < 0 {
                    n = len(bytes) + n
                } else if n > len(bytes) {
                    n = len(bytes)
                }
                return NewDBytes(DBytes(bytes[:n])), nil
            },
            Info: "Returns the first `return_set` bytes from `input`.",
        },
        Builtin{
            Types:      ArgTypes{{"input", TypeString}, {"return_set", TypeInt}},
            ReturnType: fixedReturnType(TypeString),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                runes := []rune(string(MustBeDString(args[0])))
                n := int(MustBeDInt(args[1]))

                if n < -len(runes) {
                    n = 0
                } else if n < 0 {
                    n = len(runes) + n
                } else if n > len(runes) {
                    n = len(runes)
                }
                return NewDString(string(runes[:n])), nil
            },
            Info: "Returns the first `return_set` characters from `input`.",
        },
    },

    "right": {
        Builtin{
            Types:      ArgTypes{{"input", TypeBytes}, {"return_set", TypeInt}},
            ReturnType: fixedReturnType(TypeBytes),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                bytes := []byte(*args[0].(*DBytes))
                n := int(MustBeDInt(args[1]))

                if n < -len(bytes) {
                    n = 0
                } else if n < 0 {
                    n = len(bytes) + n
                } else if n > len(bytes) {
                    n = len(bytes)
                }
                return NewDBytes(DBytes(bytes[len(bytes)-n:])), nil
            },
            Info: "Returns the last `return_set` bytes from `input`.",
        },
        Builtin{
            Types:      ArgTypes{{"input", TypeString}, {"return_set", TypeInt}},
            ReturnType: fixedReturnType(TypeString),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                runes := []rune(string(MustBeDString(args[0])))
                n := int(MustBeDInt(args[1]))

                if n < -len(runes) {
                    n = 0
                } else if n < 0 {
                    n = len(runes) + n
                } else if n > len(runes) {
                    n = len(runes)
                }
                return NewDString(string(runes[len(runes)-n:])), nil
            },
            Info: "Returns the last `return_set` characters from `input`.",
        },
    },

    "random": {
        Builtin{
            Types:                   ArgTypes{},
            ReturnType:              fixedReturnType(TypeFloat),
            impure:                  true,
            needsRepeatedEvaluation: true,
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                return NewDFloat(DFloat(rand.Float64())), nil
            },
            Info: "Returns a random float between 0 and 1.",
        },
    },

    "unique_rowid": {
        Builtin{
            Types:      ArgTypes{},
            ReturnType: fixedReturnType(TypeInt),
            category:   categoryIDGeneration,
            impure:     true,
            fn: func(ctx *EvalContext, args Datums) (Datum, error) {
                return NewDInt(GenerateUniqueInt(ctx.NodeID)), nil
            },
            Info: "Returns a unique ID used by CockroachDB to generate unique row IDs if a " +
                "Primary Key isn't defined for the table. The value is a combination of the " +
                " insert timestamp and the ID of the node executing the statement, which " +
                " guarantees this combination is globally unique.",
        },
    },

    "experimental_uuid_v4": {uuidV4Impl},
    "uuid_v4":              {uuidV4Impl},

    "greatest": {
        Builtin{
            Types:      HomogeneousType{},
            ReturnType: identityReturnType(0),
            category:   categoryComparison,
            fn: func(ctx *EvalContext, args Datums) (Datum, error) {
                return pickFromTuple(ctx, true, args)
            },
            Info: "Returns the element with the greatest value.",
        },
    },

    "least": {
        Builtin{
            Types:      HomogeneousType{},
            ReturnType: identityReturnType(0),
            category:   categoryComparison,
            fn: func(ctx *EvalContext, args Datums) (Datum, error) {
                return pickFromTuple(ctx, false, args)
            },
            Info: "Returns the element with the lowest value.",
        },
    },

    "experimental_strftime": {
        Builtin{
            Types:      ArgTypes{{"input", TypeTimestamp}, {"extract_format", TypeString}},
            ReturnType: fixedReturnType(TypeString),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                fromTime := args[0].(*DTimestamp).Time
                format := string(MustBeDString(args[1]))
                t, err := strtime.Strftime(fromTime, format)
                if err != nil {
                    return nil, err
                }
                return NewDString(t), nil
            },
            Info: "From `input`, extracts and formats the time as identified in `extract_format` " +
                "using standard `strftime` notation (though not all formatting is supported).",
        },
        Builtin{
            Types:      ArgTypes{{"input", TypeDate}, {"extract_format", TypeString}},
            ReturnType: fixedReturnType(TypeString),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                fromTime := time.Unix(int64(*args[0].(*DDate))*secondsInDay, 0).UTC()
                format := string(MustBeDString(args[1]))
                t, err := strtime.Strftime(fromTime, format)
                if err != nil {
                    return nil, err
                }
                return NewDString(t), nil
            },
            Info: "From `input`, extracts and formats the time as identified in `extract_format` " +
                "using standard `strftime` notation (though not all formatting is supported).",
        },
        Builtin{
            Types:      ArgTypes{{"input", TypeTimestampTZ}, {"extract_format", TypeString}},
            ReturnType: fixedReturnType(TypeString),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                fromTime := args[0].(*DTimestampTZ).Time
                format := string(MustBeDString(args[1]))
                t, err := strtime.Strftime(fromTime, format)
                if err != nil {
                    return nil, err
                }
                return NewDString(t), nil
            },
            Info: "From `input`, extracts and formats the time as identified in `extract_format` " +
                "using standard `strftime` notation (though not all formatting is supported).",
        },
    },

    "experimental_strptime": {
        Builtin{
            Types:      ArgTypes{{"input", TypeString}, {"format", TypeString}},
            ReturnType: fixedReturnType(TypeTimestampTZ),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                toParse := string(MustBeDString(args[0]))
                format := string(MustBeDString(args[1]))
                t, err := strtime.Strptime(toParse, format)
                if err != nil {
                    return nil, err
                }
                return MakeDTimestampTZ(t.UTC(), time.Microsecond), nil
            },
            Info: "Returns `input` as a timestamptz using `format` (which uses standard " +
                "`strptime` formatting).",
        },
    },

    "age": {
        Builtin{
            Types:      ArgTypes{{"val", TypeTimestampTZ}},
            ReturnType: fixedReturnType(TypeInterval),
            fn: func(ctx *EvalContext, args Datums) (Datum, error) {
                return timestampMinusBinOp.fn(ctx, ctx.GetTxnTimestamp(time.Microsecond), args[0])
            },
            Info: "Calculates the interval between `val` and the current time.",
        },
        Builtin{
            Types:      ArgTypes{{"begin", TypeTimestampTZ}, {"end", TypeTimestampTZ}},
            ReturnType: fixedReturnType(TypeInterval),
            fn: func(ctx *EvalContext, args Datums) (Datum, error) {
                return timestampMinusBinOp.fn(ctx, args[0], args[1])
            },
            Info: "Calculates the interval between `begin` and `end`.",
        },
    },

    "current_date": {
        Builtin{
            Types:      ArgTypes{},
            ReturnType: fixedReturnType(TypeDate),
            fn: func(ctx *EvalContext, args Datums) (Datum, error) {
                t := ctx.GetTxnTimestamp(time.Microsecond).Time
                return NewDDateFromTime(t, ctx.GetLocation()), nil
            },
            Info: "Returns the current date.",
        },
    },

    "now":                   txnTSImpl,
    "current_timestamp":     txnTSImpl,
    "transaction_timestamp": txnTSImpl,

    "statement_timestamp": {
        Builtin{
            Types:             ArgTypes{},
            ReturnType:        fixedReturnType(TypeTimestampTZ),
            preferredOverload: true,
            impure:            true,
            fn: func(ctx *EvalContext, args Datums) (Datum, error) {
                return MakeDTimestampTZ(ctx.GetStmtTimestamp(), time.Microsecond), nil
            },
            Info: "Returns the current statement's timestamp.",
        },
        Builtin{
            Types:      ArgTypes{},
            ReturnType: fixedReturnType(TypeTimestamp),
            impure:     true,
            fn: func(ctx *EvalContext, args Datums) (Datum, error) {
                return MakeDTimestamp(ctx.GetStmtTimestamp(), time.Microsecond), nil
            },
            Info: "Returns the current statement's timestamp.",
        },
    },

    "cluster_logical_timestamp": {
        Builtin{
            Types:      ArgTypes{},
            ReturnType: fixedReturnType(TypeDecimal),
            category:   categorySystemInfo,
            impure:     true,
            fn: func(ctx *EvalContext, args Datums) (Datum, error) {
                return ctx.GetClusterTimestamp(), nil
            },
            Info: "This function is used only by CockroachDB's developers for testing purposes.",
        },
    },

    "clock_timestamp": {
        Builtin{
            Types:             ArgTypes{},
            ReturnType:        fixedReturnType(TypeTimestampTZ),
            preferredOverload: true,
            impure:            true,
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                return MakeDTimestampTZ(timeutil.Now(), time.Microsecond), nil
            },
            Info: "Returns the current wallclock time.",
        },
        Builtin{
            Types:      ArgTypes{},
            ReturnType: fixedReturnType(TypeTimestamp),
            impure:     true,
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                return MakeDTimestamp(timeutil.Now(), time.Microsecond), nil
            },
            Info: "Returns the current wallclock time.",
        },
    },

    "extract": {
        Builtin{
            Types:      ArgTypes{{"element", TypeString}, {"input", TypeTimestamp}},
            ReturnType: fixedReturnType(TypeInt),
            category:   categoryDateAndTime,
            fn: func(ctx *EvalContext, args Datums) (Datum, error) {

                fromTS := args[1].(*DTimestamp)
                timeSpan := strings.ToLower(string(MustBeDString(args[0])))
                return extractStringFromTimestamp(ctx, fromTS.Time, timeSpan)
            },
            Info: "Extracts `element` from `input`. Compatible `elements` are: <br/>&#8226; " +
                "year<br/>&#8226; quarter<br/>&#8226; month<br/>&#8226; week<br/>&#8226; " +
                "dayofweek<br/>&#8226; dayofyear<br/>&#8226; hour<br/>&#8226; minute<br/>&#8226; " +
                "second<br/>&#8226; millisecond<br/>&#8226; microsecond<br/>&#8226; epoch",
        },
        Builtin{
            Types:      ArgTypes{{"element", TypeString}, {"input", TypeDate}},
            ReturnType: fixedReturnType(TypeInt),
            category:   categoryDateAndTime,
            fn: func(ctx *EvalContext, args Datums) (Datum, error) {
                timeSpan := strings.ToLower(string(MustBeDString(args[0])))
                date := args[1].(*DDate)
                fromTSTZ := MakeDTimestampTZFromDate(ctx.GetLocation(), date)
                return extractStringFromTimestamp(ctx, fromTSTZ.Time, timeSpan)
            },
            Info: "Extracts `element` from `input`. Compatible `elements` are: <br/>&#8226; " +
                "year<br/>&#8226; quarter<br/>&#8226; month<br/>&#8226; week<br/>&#8226; " +
                "dayofweek<br/>&#8226; dayofyear<br/>&#8226; hour<br/>&#8226; minute<br/>&#8226; " +
                "second<br/>&#8226; millisecond<br/>&#8226; microsecond<br/>&#8226; epoch",
        },
    },

    "extract_duration": {
        Builtin{
            Types:      ArgTypes{{"element", TypeString}, {"input", TypeInterval}},
            ReturnType: fixedReturnType(TypeInt),
            category:   categoryDateAndTime,
            fn: func(_ *EvalContext, args Datums) (Datum, error) {

                fromInterval := *args[1].(*DInterval)
                timeSpan := strings.ToLower(string(MustBeDString(args[0])))
                switch timeSpan {
                case "hour", "hours":
                    return NewDInt(DInt(fromInterval.Nanos / int64(time.Hour))), nil

                case "minute", "minutes":
                    return NewDInt(DInt(fromInterval.Nanos / int64(time.Minute))), nil

                case "second", "seconds":
                    return NewDInt(DInt(fromInterval.Nanos / int64(time.Second))), nil

                case "millisecond", "milliseconds":

                    return NewDInt(DInt(fromInterval.Nanos / int64(time.Millisecond))), nil

                case "microsecond", "microseconds":
                    return NewDInt(DInt(fromInterval.Nanos / int64(time.Microsecond))), nil

                default:
                    return nil, fmt.Errorf("unsupported timespan: %s", timeSpan)
                }
            },
            Info: "Extracts `element` from `input`. Compatible `elements` are: <br/>&#8226; hour" +
                "<br/>&#8226; minute<br/>&#8226; second<br/>&#8226; millisecond<br/>&#8226; " +
                "microsecond",
        },
    },

    "abs": {
        floatBuiltin1(func(x float64) (Datum, error) {
            return NewDFloat(DFloat(math.Abs(x))), nil
        }, "Calculates the absolute value of `val`."),
        decimalBuiltin1(func(x *apd.Decimal) (Datum, error) {
            dd := &DDecimal{}
            dd.Abs(x)
            return dd, nil
        }, "Calculates the absolute value of `val`."),
        Builtin{
            Types:      ArgTypes{{"val", TypeInt}},
            ReturnType: fixedReturnType(TypeInt),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                x := MustBeDInt(args[0])
                switch {
                case x == math.MinInt64:
                    return nil, errAbsOfMinInt64
                case x < 0:
                    return NewDInt(-x), nil
                }
                return args[0], nil
            },
            Info: "Calculates the absolute value of `val`.",
        },
    },

    "acos": {
        floatBuiltin1(func(x float64) (Datum, error) {
            return NewDFloat(DFloat(math.Acos(x))), nil
        }, "Calculates the inverse cosine of `val`."),
    },

    "asin": {
        floatBuiltin1(func(x float64) (Datum, error) {
            return NewDFloat(DFloat(math.Asin(x))), nil
        }, "Calculates the inverse sine of `val`."),
    },

    "atan": {
        floatBuiltin1(func(x float64) (Datum, error) {
            return NewDFloat(DFloat(math.Atan(x))), nil
        }, "Calculates the inverse tangent of `val`."),
    },

    "atan2": {
        floatBuiltin2("x", "y", func(x, y float64) (Datum, error) {
            return NewDFloat(DFloat(math.Atan2(x, y))), nil
        }, "Calculates the inverse tangent of `x`/`y`."),
    },

    "cbrt": {
        floatBuiltin1(func(x float64) (Datum, error) {
            return NewDFloat(DFloat(math.Cbrt(x))), nil
        }, "Calculates the cube root (&#8731;) of `val`."),
        decimalBuiltin1(func(x *apd.Decimal) (Datum, error) {
            dd := &DDecimal{}
            _, err := DecimalCtx.Cbrt(&dd.Decimal, x)
            return dd, err
        }, "Calculates the cube root (&#8731;) of `val`."),
    },

    "ceil":    ceilImpl,
    "ceiling": ceilImpl,

    "cos": {
        floatBuiltin1(func(x float64) (Datum, error) {
            return NewDFloat(DFloat(math.Cos(x))), nil
        }, "Calculates the cosine of `val`."),
    },

    "cot": {
        floatBuiltin1(func(x float64) (Datum, error) {
            return NewDFloat(DFloat(1 / math.Tan(x))), nil
        }, "Calculates the cotangent of `val`."),
    },

    "degrees": {
        floatBuiltin1(func(x float64) (Datum, error) {
            return NewDFloat(DFloat(180.0 * x / math.Pi)), nil
        }, "Converts `val` as a radian value to a degree value."),
    },

    "div": {
        floatBuiltin2("x", "y", func(x, y float64) (Datum, error) {
            return NewDFloat(DFloat(math.Trunc(x / y))), nil
        }, "Calculates the integer quotient of `x`/`y`."),
        decimalBuiltin2("x", "y", func(x, y *apd.Decimal) (Datum, error) {
            if y.Sign() == 0 {
                return nil, errDivByZero
            }
            dd := &DDecimal{}
            _, err := HighPrecisionCtx.QuoInteger(&dd.Decimal, x, y)
            return dd, err
        }, "Calculates the integer quotient of `x`/`y`."),
        {
            Types:      ArgTypes{{"x", TypeInt}, {"y", TypeInt}},
            ReturnType: fixedReturnType(TypeInt),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                y := MustBeDInt(args[1])
                if y == 0 {
                    return nil, errDivByZero
                }
                x := MustBeDInt(args[0])
                return NewDInt(x / y), nil
            },
            Info: "Calculates the integer quotient of `x`/`y`.",
        },
    },

    "exp": {
        floatBuiltin1(func(x float64) (Datum, error) {
            return NewDFloat(DFloat(math.Exp(x))), nil
        }, "Calculates *e* ^ `val`."),
        decimalBuiltin1(func(x *apd.Decimal) (Datum, error) {
            dd := &DDecimal{}
            _, err := DecimalCtx.Exp(&dd.Decimal, x)
            return dd, err
        }, "Calculates *e* ^ `val`."),
    },

    "floor": {
        floatBuiltin1(func(x float64) (Datum, error) {
            return NewDFloat(DFloat(math.Floor(x))), nil
        }, "Calculates the largest integer not greater than `val`."),
        decimalBuiltin1(func(x *apd.Decimal) (Datum, error) {
            dd := &DDecimal{}
            _, err := ExactCtx.Floor(&dd.Decimal, x)
            return dd, err
        }, "Calculates the largest integer not greater than `val`."),
    },

    "isnan": {
        Builtin{

            Types:      ArgTypes{{"val", TypeFloat}},
            ReturnType: fixedReturnType(TypeBool),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                return MakeDBool(DBool(isNaN(args[0]))), nil
            },
            Info: "Returns true if `val` is NaN, false otherwise.",
        },
        Builtin{
            Types:      ArgTypes{{"val", TypeDecimal}},
            ReturnType: fixedReturnType(TypeBool),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                return MakeDBool(DBool(isNaN(args[0]))), nil
            },
            Info: "Returns true if `val` is NaN, false otherwise.",
        },
    },

    "ln": {
        floatBuiltin1(func(x float64) (Datum, error) {
            return NewDFloat(DFloat(math.Log(x))), nil
        }, "Calculates the natural log of `val`."),
        decimalLogFn(DecimalCtx.Ln, "Calculates the natural log of `val`."),
    },

    "log": {
        floatBuiltin1(func(x float64) (Datum, error) {
            return NewDFloat(DFloat(math.Log10(x))), nil
        }, "Calculates the base 10 log of `val`."),
        decimalLogFn(DecimalCtx.Log10, "Calculates the base 10 log of `val`."),
    },

    "mod": {
        floatBuiltin2("x", "y", func(x, y float64) (Datum, error) {
            return NewDFloat(DFloat(math.Mod(x, y))), nil
        }, "Calculates `x`%`y`."),
        decimalBuiltin2("x", "y", func(x, y *apd.Decimal) (Datum, error) {
            if y.Sign() == 0 {
                return nil, errZeroModulus
            }
            dd := &DDecimal{}
            _, err := HighPrecisionCtx.Rem(&dd.Decimal, x, y)
            return dd, err
        }, "Calculates `x`%`y`."),
        Builtin{
            Types:      ArgTypes{{"x", TypeInt}, {"y", TypeInt}},
            ReturnType: fixedReturnType(TypeInt),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                y := MustBeDInt(args[1])
                if y == 0 {
                    return nil, errZeroModulus
                }
                x := MustBeDInt(args[0])
                return NewDInt(x % y), nil
            },
            Info: "Calculates `x`%`y`.",
        },
    },

    "pi": {
        Builtin{
            Types:      ArgTypes{},
            ReturnType: fixedReturnType(TypeFloat),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                return NewDFloat(math.Pi), nil
            },
            Info: "Returns the value for pi (3.141592653589793).",
        },
    },

    "pow":   powImpls,
    "power": powImpls,

    "radians": {
        floatBuiltin1(func(x float64) (Datum, error) {
            return NewDFloat(DFloat(x * math.Pi / 180.0)), nil
        }, "Converts `val` as a degree value to a radians value."),
    },

    "round": {
        floatBuiltin1(func(x float64) (Datum, error) {
            return NewDFloat(DFloat(round(x))), nil
        }, "Rounds `val` to the nearest integer using half to even (banker's) rounding."),
        decimalBuiltin1(func(x *apd.Decimal) (Datum, error) {
            return roundDecimal(x, 0)
        }, "Rounds `val` to the nearest integer, half away from zero: "+
            "ROUND(+/-2.4) = +/-2, ROUND(+/-2.5) = +/-3."),
        Builtin{
            Types:      ArgTypes{{"input", TypeFloat}, {"decimal_accuracy", TypeInt}},
            ReturnType: fixedReturnType(TypeFloat),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                var x apd.Decimal
                if _, err := x.SetFloat64(float64(*args[0].(*DFloat))); err != nil {
                    return nil, err
                }

                scale := int32(MustBeDInt(args[1]))

                var d apd.Decimal
                if _, err := RoundCtx.Quantize(&d, &x, -scale); err != nil {
                    return nil, err
                }

                f, err := d.Float64()
                if err != nil {
                    return nil, err
                }

                return NewDFloat(DFloat(f)), nil
            },
            Info: "Keeps `decimal_accuracy` number of figures to the right of the zero position " +
                " in `input` using half to even (banker's) rounding.",
        },
        Builtin{
            Types:      ArgTypes{{"input", TypeDecimal}, {"decimal_accuracy", TypeInt}},
            ReturnType: fixedReturnType(TypeDecimal),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {

                scale := int32(MustBeDInt(args[1]))
                return roundDecimal(&args[0].(*DDecimal).Decimal, scale)
            },
            Info: "Keeps `decimal_accuracy` number of figures to the right of the zero position " +
                " in `input using half away from zero rounding. If `decimal_accuracy` " +
                "is not in the range -2^31...(2^31-1), the results are undefined.",
        },
    },

    "sin": {
        floatBuiltin1(func(x float64) (Datum, error) {
            return NewDFloat(DFloat(math.Sin(x))), nil
        }, "Calculates the sine of `val`."),
    },

    "sign": {
        floatBuiltin1(func(x float64) (Datum, error) {
            switch {
            case x < 0:
                return NewDFloat(-1), nil
            case x == 0:
                return NewDFloat(0), nil
            }
            return NewDFloat(1), nil
        }, "Determines the sign of `val`: **1** for positive; **0** for 0 values; **-1** for "+
            "negative."),
        decimalBuiltin1(func(x *apd.Decimal) (Datum, error) {
            d := &DDecimal{}
            d.Decimal.SetCoefficient(int64(x.Sign()))
            return d, nil
        }, "Determines the sign of `val`: **1** for positive; **0** for 0 values; **-1** for "+
            "negative."),
        Builtin{
            Types:      ArgTypes{{"val", TypeInt}},
            ReturnType: fixedReturnType(TypeInt),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                x := MustBeDInt(args[0])
                switch {
                case x < 0:
                    return NewDInt(-1), nil
                case x == 0:
                    return DZero, nil
                }
                return NewDInt(1), nil
            },
            Info: "Determines the sign of `val`: **1** for positive; **0** for 0 values; **-1** " +
                "for negative.",
        },
    },

    "sqrt": {
        floatBuiltin1(func(x float64) (Datum, error) {

            if x < 0 {
                return nil, errSqrtOfNegNumber
            }
            return NewDFloat(DFloat(math.Sqrt(x))), nil
        }, "Calculates the square root of `val`."),
        decimalBuiltin1(func(x *apd.Decimal) (Datum, error) {
            if x.Sign() < 0 {
                return nil, errSqrtOfNegNumber
            }
            dd := &DDecimal{}
            _, err := DecimalCtx.Sqrt(&dd.Decimal, x)
            return dd, err
        }, "Calculates the square root of `val`."),
    },

    "tan": {
        floatBuiltin1(func(x float64) (Datum, error) {
            return NewDFloat(DFloat(math.Tan(x))), nil
        }, "Calculates the tangent of `val`."),
    },

    "trunc": {
        floatBuiltin1(func(x float64) (Datum, error) {
            return NewDFloat(DFloat(math.Trunc(x))), nil
        }, "Truncates the decimal values of `val`."),
        decimalBuiltin1(func(x *apd.Decimal) (Datum, error) {

            dd := &DDecimal{}
            frac := new(apd.Decimal)
            x.Modf(&dd.Decimal, frac)
            return dd, nil
        }, "Truncates the decimal values of `val`."),
    },

    "to_english": {
        Builtin{
            Types:      ArgTypes{{"val", TypeInt}},
            ReturnType: fixedReturnType(TypeString),
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                val := int(*args[0].(*DInt))
                var buf bytes.Buffer
                if val < 0 {
                    buf.WriteString("minus-")
                    val = -val
                }
                var digits []string
                digits = append(digits, digitNames[val%10])
                for val > 9 {
                    val /= 10
                    digits = append(digits, digitNames[val%10])
                }
                for i := len(digits) - 1; i >= 0; i-- {
                    if i < len(digits)-1 {
                        buf.WriteByte('-')
                    }
                    buf.WriteString(digits[i])
                }
                return NewDString(buf.String()), nil
            },
            category: categoryString,
            Info:     "This function enunciates the value of its argument using English cardinals.",
        },
    },

    "array_length": {
        Builtin{
            Types:      ArgTypes{{"input", TypeAnyArray}, {"array_dimension", TypeInt}},
            ReturnType: fixedReturnType(TypeInt),
            category:   categorySystemInfo,
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                arr := MustBeDArray(args[0])
                dimen := int64(MustBeDInt(args[1]))
                return arrayLength(arr, dimen), nil
            },
            Info: "Calculates the length of `input` on the provided `array_dimension`. However, " +
                "because CockroachDB doesn't yet support multi-dimensional arrays, the only supported" +
                " `array_dimension` is **1**.",
        },
    },

    "array_lower": {
        Builtin{
            Types:      ArgTypes{{"input", TypeAnyArray}, {"array_dimension", TypeInt}},
            ReturnType: fixedReturnType(TypeInt),
            category:   categorySystemInfo,
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                arr := MustBeDArray(args[0])
                dimen := int64(MustBeDInt(args[1]))
                return arrayLower(arr, dimen), nil
            },
            Info: "Calculates the minimum value of `input` on the provided `array_dimension`. " +
                "However, because CockroachDB doesn't yet support multi-dimensional arrays, the only " +
                "supported `array_dimension` is **1**.",
        },
    },

    "array_upper": {
        Builtin{
            Types:      ArgTypes{{"input", TypeAnyArray}, {"array_dimension", TypeInt}},
            ReturnType: fixedReturnType(TypeInt),
            category:   categorySystemInfo,
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                arr := MustBeDArray(args[0])
                dimen := int64(MustBeDInt(args[1]))
                return arrayLength(arr, dimen), nil
            },
            Info: "Calculates the maximum value of `input` on the provided `array_dimension`. " +
                "However, because CockroachDB doesn't yet support multi-dimensional arrays, the only " +
                "supported `array_dimension` is **1**.",
        },
    },

    "version": {
        Builtin{
            Types:      ArgTypes{},
            ReturnType: fixedReturnType(TypeString),
            category:   categorySystemInfo,
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                return NewDString(build.GetInfo().Short()), nil
            },
            Info: "Returns the node's version of CockroachDB.",
        },
    },

    "current_database": {
        Builtin{
            Types:      ArgTypes{},
            ReturnType: fixedReturnType(TypeString),
            category:   categorySystemInfo,
            fn: func(ctx *EvalContext, args Datums) (Datum, error) {
                if len(ctx.Database) == 0 {
                    return DNull, nil
                }
                return NewDString(ctx.Database), nil
            },
            Info: "Returns the current database.",
        },
    },

    "current_schema": {
        Builtin{
            Types:      ArgTypes{},
            ReturnType: fixedReturnType(TypeString),
            category:   categorySystemInfo,
            fn: func(ctx *EvalContext, args Datums) (Datum, error) {
                if len(ctx.Database) == 0 {
                    return DNull, nil
                }
                return NewDString(ctx.Database), nil
            },
            Info: "Returns the current schema. This function is provided for " +
                "compatibility with PostgreSQL. For a new CockroachDB application, " +
                "consider using current_database() instead.",
        },
    },

    "current_schemas": {
        Builtin{
            Types:      ArgTypes{{"include_pg_catalog", TypeBool}},
            ReturnType: fixedReturnType(TypeStringArray),
            category:   categorySystemInfo,
            fn: func(ctx *EvalContext, args Datums) (Datum, error) {
                includePgCatalog := *(args[0].(*DBool))
                schemas := NewDArray(TypeString)
                if len(ctx.Database) != 0 {
                    if err := schemas.Append(NewDString(ctx.Database)); err != nil {
                        return nil, err
                    }
                }
                for _, p := range ctx.SearchPath {
                    if !includePgCatalog && p == "pg_catalog" {
                        continue
                    }
                    if err := schemas.Append(NewDString(p)); err != nil {
                        return nil, err
                    }
                }
                return schemas, nil
            },
            Info: "Returns the current search path for unqualified names.",
        },
    },

    "crdb_internal.cluster_id": {
        Builtin{
            Types:      ArgTypes{},
            ReturnType: fixedReturnType(TypeUUID),
            category:   categorySystemInfo,
            fn: func(ctx *EvalContext, args Datums) (Datum, error) {
                return NewDUuid(DUuid{ctx.ClusterID}), nil
            },
            Info: "Returns the cluster ID.",
        },
    },

    "crdb_internal.force_internal_error": {
        Builtin{
            Types:      ArgTypes{{"msg", TypeString}},
            ReturnType: fixedReturnType(TypeInt),
            impure:     true,
            privileged: true,
            fn: func(ctx *EvalContext, args Datums) (Datum, error) {
                msg := string(*args[0].(*DString))
                return nil, pgerror.NewError(pgerror.CodeInternalError, msg)
            },
            category: categorySystemInfo,
            Info:     "This function is used only by CockroachDB's developers for testing purposes.",
        },
    },

    "crdb_internal.force_panic": {
        Builtin{
            Types:      ArgTypes{{"msg", TypeString}},
            ReturnType: fixedReturnType(TypeInt),
            impure:     true,
            privileged: true,
            fn: func(ctx *EvalContext, args Datums) (Datum, error) {
                msg := string(*args[0].(*DString))
                panic(msg)
            },
            category: categorySystemInfo,
            Info:     "This function is used only by CockroachDB's developers for testing purposes.",
        },
    },

    "crdb_internal.force_log_fatal": {
        Builtin{
            Types:      ArgTypes{{"msg", TypeString}},
            ReturnType: fixedReturnType(TypeInt),
            impure:     true,
            privileged: true,
            fn: func(ctx *EvalContext, args Datums) (Datum, error) {
                msg := string(*args[0].(*DString))
                log.Fatal(ctx.Ctx(), msg)
                return nil, nil
            },
            category: categorySystemInfo,
            Info:     "This function is used only by CockroachDB's developers for testing purposes.",
        },
    },

    "crdb_internal.force_retry": {
        Builtin{
            Types:      ArgTypes{{"val", TypeInterval}},
            ReturnType: fixedReturnType(TypeInt),
            impure:     true,
            privileged: true,
            fn: func(ctx *EvalContext, args Datums) (Datum, error) {
                minDuration := args[0].(*DInterval).Duration
                elapsed := duration.Duration{
                    Nanos: int64(ctx.stmtTimestamp.Sub(ctx.txnTimestamp)),
                }
                if elapsed.Compare(minDuration) < 0 {
                    return nil, roachpb.NewHandledRetryableTxnError(
                        "forced by crdb_internal.force_retry()",
                        nil,
                        roachpb.Transaction{})
                }
                return DZero, nil
            },
            category: categorySystemInfo,
            Info:     "This function is used only by CockroachDB's developers for testing purposes.",
        },
        Builtin{
            Types: ArgTypes{
                {"val", TypeInterval},
                {"txnID", TypeString}},
            ReturnType: fixedReturnType(TypeInt),
            impure:     true,
            fn: func(ctx *EvalContext, args Datums) (Datum, error) {
                minDuration := args[0].(*DInterval).Duration
                txnID := args[1].(*DString)
                elapsed := duration.Duration{
                    Nanos: int64(ctx.stmtTimestamp.Sub(ctx.txnTimestamp)),
                }
                if elapsed.Compare(minDuration) < 0 {
                    uuid, err := uuid.FromString(string(*txnID))
                    if err != nil {
                        return nil, err
                    }
                    return nil, roachpb.NewHandledRetryableTxnError(
                        "forced by crdb_internal.force_retry()", &uuid, roachpb.Transaction{})
                }
                return DZero, nil
            },
            category: categorySystemInfo,
            Info:     "This function is used only by CockroachDB's developers for testing purposes.",
        },
    },

    "crdb_internal.no_constant_folding": {
        Builtin{
            Types:      ArgTypes{{"input", TypeAny}},
            ReturnType: identityReturnType(0),
            impure:     true,
            fn: func(_ *EvalContext, args Datums) (Datum, error) {
                return args[0], nil
            },
            category: categorySystemInfo,
            Info:     "This function is used only by CockroachDB's developers for testing purposes.",
        },
    },
}

Builtins contains the built-in functions indexed by name.

var CmpOps = map[ComparisonOperator]cmpOpOverload{
    EQ: {
        CmpOp{
            LeftType:  TypeString,
            RightType: TypeString,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeCollatedString,
            RightType: TypeCollatedString,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeBytes,
            RightType: TypeBytes,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeBool,
            RightType: TypeBool,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeInt,
            RightType: TypeInt,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeFloat,
            RightType: TypeFloat,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeDecimal,
            RightType: TypeDecimal,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeFloat,
            RightType: TypeInt,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeInt,
            RightType: TypeFloat,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeDecimal,
            RightType: TypeInt,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeInt,
            RightType: TypeDecimal,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeDecimal,
            RightType: TypeFloat,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeFloat,
            RightType: TypeDecimal,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeDate,
            RightType: TypeDate,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeTimestamp,
            RightType: TypeTimestamp,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeTimestampTZ,
            RightType: TypeTimestampTZ,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeTimestamp,
            RightType: TypeTimestampTZ,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeTimestampTZ,
            RightType: TypeTimestamp,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeDate,
            RightType: TypeTimestampTZ,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeDate,
            RightType: TypeTimestamp,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeTimestampTZ,
            RightType: TypeDate,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeTimestamp,
            RightType: TypeDate,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeInterval,
            RightType: TypeInterval,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeUUID,
            RightType: TypeUUID,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeOid,
            RightType: TypeOid,
            fn:        cmpOpScalarEQFn,
        },
        CmpOp{
            LeftType:  TypeTuple,
            RightType: TypeTuple,
            fn: func(ctx *EvalContext, left Datum, right Datum) (Datum, error) {
                return cmpOpTupleFn(ctx, *left.(*DTuple), *right.(*DTuple), EQ), nil
            },
        },
    },

    LT: {
        CmpOp{
            LeftType:  TypeString,
            RightType: TypeString,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeCollatedString,
            RightType: TypeCollatedString,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeBytes,
            RightType: TypeBytes,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeBool,
            RightType: TypeBool,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeInt,
            RightType: TypeInt,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeFloat,
            RightType: TypeFloat,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeDecimal,
            RightType: TypeDecimal,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeFloat,
            RightType: TypeInt,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeInt,
            RightType: TypeFloat,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeDecimal,
            RightType: TypeInt,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeInt,
            RightType: TypeDecimal,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeDecimal,
            RightType: TypeFloat,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeFloat,
            RightType: TypeDecimal,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeDate,
            RightType: TypeDate,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeTimestamp,
            RightType: TypeTimestamp,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeTimestampTZ,
            RightType: TypeTimestampTZ,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeTimestamp,
            RightType: TypeTimestampTZ,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeTimestampTZ,
            RightType: TypeTimestamp,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeDate,
            RightType: TypeTimestampTZ,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeDate,
            RightType: TypeTimestamp,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeTimestampTZ,
            RightType: TypeDate,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeTimestamp,
            RightType: TypeDate,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeInterval,
            RightType: TypeInterval,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeUUID,
            RightType: TypeUUID,
            fn:        cmpOpScalarLTFn,
        },
        CmpOp{
            LeftType:  TypeTuple,
            RightType: TypeTuple,
            fn: func(ctx *EvalContext, left Datum, right Datum) (Datum, error) {
                return cmpOpTupleFn(ctx, *left.(*DTuple), *right.(*DTuple), LT), nil
            },
        },
    },

    LE: {
        CmpOp{
            LeftType:  TypeString,
            RightType: TypeString,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeCollatedString,
            RightType: TypeCollatedString,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeBytes,
            RightType: TypeBytes,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeBool,
            RightType: TypeBool,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeInt,
            RightType: TypeInt,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeFloat,
            RightType: TypeFloat,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeDecimal,
            RightType: TypeDecimal,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeFloat,
            RightType: TypeInt,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeInt,
            RightType: TypeFloat,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeDecimal,
            RightType: TypeInt,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeInt,
            RightType: TypeDecimal,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeDecimal,
            RightType: TypeFloat,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeFloat,
            RightType: TypeDecimal,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeDate,
            RightType: TypeDate,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeTimestamp,
            RightType: TypeTimestamp,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeTimestampTZ,
            RightType: TypeTimestampTZ,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeTimestampTZ,
            RightType: TypeTimestamp,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeTimestamp,
            RightType: TypeTimestampTZ,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeDate,
            RightType: TypeTimestampTZ,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeDate,
            RightType: TypeTimestamp,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeTimestampTZ,
            RightType: TypeDate,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeTimestamp,
            RightType: TypeDate,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeInterval,
            RightType: TypeInterval,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeUUID,
            RightType: TypeUUID,
            fn:        cmpOpScalarLEFn,
        },
        CmpOp{
            LeftType:  TypeTuple,
            RightType: TypeTuple,
            fn: func(ctx *EvalContext, left Datum, right Datum) (Datum, error) {
                return cmpOpTupleFn(ctx, *left.(*DTuple), *right.(*DTuple), LE), nil
            },
        },
    },

    In: {
        makeEvalTupleIn(TypeBool),
        makeEvalTupleIn(TypeInt),
        makeEvalTupleIn(TypeFloat),
        makeEvalTupleIn(TypeDecimal),
        makeEvalTupleIn(TypeString),
        makeEvalTupleIn(TypeCollatedString),
        makeEvalTupleIn(TypeBytes),
        makeEvalTupleIn(TypeDate),
        makeEvalTupleIn(TypeTimestamp),
        makeEvalTupleIn(TypeTimestampTZ),
        makeEvalTupleIn(TypeInterval),
        makeEvalTupleIn(TypeUUID),
        makeEvalTupleIn(TypeTuple),
        makeEvalTupleIn(TypeOid),
    },

    Like: {
        CmpOp{
            LeftType:  TypeString,
            RightType: TypeString,
            fn: func(ctx *EvalContext, left Datum, right Datum) (Datum, error) {
                return matchLike(ctx, left, right, false)
            },
        },
    },

    ILike: {
        CmpOp{
            LeftType:  TypeString,
            RightType: TypeString,
            fn: func(ctx *EvalContext, left Datum, right Datum) (Datum, error) {
                return matchLike(ctx, left, right, true)
            },
        },
    },

    SimilarTo: {
        CmpOp{
            LeftType:  TypeString,
            RightType: TypeString,
            fn: func(ctx *EvalContext, left Datum, right Datum) (Datum, error) {
                key := similarToKey(MustBeDString(right))
                return matchRegexpWithKey(ctx, left, key)
            },
        },
    },

    RegMatch: {
        CmpOp{
            LeftType:  TypeString,
            RightType: TypeString,
            fn: func(ctx *EvalContext, left Datum, right Datum) (Datum, error) {
                key := regexpKey{s: string(MustBeDString(right)), caseInsensitive: false}
                return matchRegexpWithKey(ctx, left, key)
            },
        },
    },

    RegIMatch: {
        CmpOp{
            LeftType:  TypeString,
            RightType: TypeString,
            fn: func(ctx *EvalContext, left Datum, right Datum) (Datum, error) {
                key := regexpKey{s: string(MustBeDString(right)), caseInsensitive: true}
                return matchRegexpWithKey(ctx, left, key)
            },
        },
    },
}

CmpOps contains the comparison operations indexed by operation type.

var Generators = map[string][]Builtin{
    "generate_series": {
        makeGeneratorBuiltin(
            ArgTypes{{"start", TypeInt}, {"end", TypeInt}},
            TTuple{TypeInt},
            makeSeriesGenerator,
            "Produces a virtual table containing the integer values from `start` to `end`, inclusive.",
        ),
        makeGeneratorBuiltin(
            ArgTypes{{"start", TypeInt}, {"end", TypeInt}, {"step", TypeInt}},
            TTuple{TypeInt},
            makeSeriesGenerator,
            "Produces a virtual table containing the integer values from `start` to `end`, inclusive, by increment of `step`.",
        ),
    },
    "unnest": {
        makeGeneratorBuiltinWithReturnType(
            ArgTypes{{"input", TypeAnyArray}},
            func(args []TypedExpr) Type {
                if len(args) == 0 {
                    return unknownReturnType
                }
                return TTable{Cols: TTuple{args[0].ResolvedType().(TArray).Typ}}
            },
            makeArrayGenerator,
            "Returns the input array as a set of rows",
        ),
    },
}

Generators is a map from name to slice of Builtins for all built-in generators.

var OidToType = map[oid.Oid]Type{
    oid.T_anyelement:   TypeAny,
    oid.T_bool:         TypeBool,
    oid.T_bytea:        TypeBytes,
    oid.T_date:         TypeDate,
    oid.T_float4:       typeFloat4,
    oid.T_float8:       TypeFloat,
    oid.T_int2:         typeInt2,
    oid.T_int4:         typeInt4,
    oid.T_int8:         TypeInt,
    oid.T_int2vector:   TypeIntVector,
    oid.T_interval:     TypeInterval,
    oid.T_name:         TypeName,
    oid.T_numeric:      TypeDecimal,
    oid.T_oid:          TypeOid,
    oid.T_regclass:     TypeRegClass,
    oid.T_regnamespace: TypeRegNamespace,
    oid.T_regproc:      TypeRegProc,
    oid.T_regprocedure: TypeRegProcedure,
    oid.T_regtype:      TypeRegType,
    oid.T__text:        TypeStringArray,
    oid.T__int2:        typeInt2Array,
    oid.T__int4:        typeInt4Array,
    oid.T__int8:        TypeIntArray,
    oid.T_record:       TypeTuple,
    oid.T_text:         TypeString,
    oid.T_timestamp:    TypeTimestamp,
    oid.T_timestamptz:  TypeTimestampTZ,
    oid.T_uuid:         TypeUUID,
    oid.T_varchar:      typeVarChar,
}

OidToType maps Postgres object IDs to CockroachDB types.

var UnaryOps = map[UnaryOperator]unaryOpOverload{
    UnaryPlus: {
        UnaryOp{
            Typ:        TypeInt,
            ReturnType: TypeInt,
            fn: func(_ *EvalContext, d Datum) (Datum, error) {
                return d, nil
            },
        },
        UnaryOp{
            Typ:        TypeFloat,
            ReturnType: TypeFloat,
            fn: func(_ *EvalContext, d Datum) (Datum, error) {
                return d, nil
            },
        },
        UnaryOp{
            Typ:        TypeDecimal,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, d Datum) (Datum, error) {
                return d, nil
            },
        },
    },

    UnaryMinus: {
        UnaryOp{
            Typ:        TypeInt,
            ReturnType: TypeInt,
            fn: func(_ *EvalContext, d Datum) (Datum, error) {
                i := MustBeDInt(d)
                if i == math.MinInt64 {
                    return nil, errIntOutOfRange
                }
                return NewDInt(-i), nil
            },
        },
        UnaryOp{
            Typ:        TypeFloat,
            ReturnType: TypeFloat,
            fn: func(_ *EvalContext, d Datum) (Datum, error) {
                return NewDFloat(-*d.(*DFloat)), nil
            },
        },
        UnaryOp{
            Typ:        TypeDecimal,
            ReturnType: TypeDecimal,
            fn: func(_ *EvalContext, d Datum) (Datum, error) {
                dec := &d.(*DDecimal).Decimal
                dd := &DDecimal{}
                dd.Decimal.Neg(dec)
                return dd, nil
            },
        },
        UnaryOp{
            Typ:        TypeInterval,
            ReturnType: TypeInterval,
            fn: func(_ *EvalContext, d Datum) (Datum, error) {
                i := d.(*DInterval).Duration
                i.Nanos = -i.Nanos
                i.Days = -i.Days
                i.Months = -i.Months
                return &DInterval{Duration: i}, nil
            },
        },
    },

    UnaryComplement: {
        UnaryOp{
            Typ:        TypeInt,
            ReturnType: TypeInt,
            fn: func(_ *EvalContext, d Datum) (Datum, error) {
                return NewDInt(^MustBeDInt(d)), nil
            },
        },
    },
}

UnaryOps contains the unary operations indexed by operation type.

func AsString Uses

func AsString(n NodeFormatter) string

AsString pretty prints a node to a string.

func AsStringWithFlags Uses

func AsStringWithFlags(n NodeFormatter, f FmtFlags) string

AsStringWithFlags pretty prints a node to a string given specific flags.

func ContainsVars Uses

func ContainsVars(expr Expr) bool

ContainsVars returns true if the expression contains any variables. (variables = sub-expressions, placeholders, indexed vars, etc.)

func ExprDebugString Uses

func ExprDebugString(expr Expr) string

ExprDebugString generates a multi-line debug string with one node per line in Go format.

func FindEqualComparisonFunction Uses

func FindEqualComparisonFunction(
    leftType, rightType Type,
) (func(*EvalContext, Datum, Datum) (Datum, error), bool)

FindEqualComparisonFunction looks up an overload of the "=" operator for a given pair of input operand types.

func FormatNode Uses

func FormatNode(buf *bytes.Buffer, f FmtFlags, n NodeFormatter)

FormatNode recurses into a node for pretty-printing. Flag-driven special cases can hook into this.

func HasReturningClause Uses

func HasReturningClause(clause ReturningClause) bool

HasReturningClause determines if a ReturningClause is present, given a variant of the ReturningClause interface.

func IsNumericOne Uses

func IsNumericOne(expr TypedExpr) bool

IsNumericOne returns true if the datum is a number and equal to one.

func IsNumericZero Uses

func IsNumericZero(expr TypedExpr) bool

IsNumericZero returns true if the datum is a number and equal to zero.

func LimitDecimalWidth Uses

func LimitDecimalWidth(d *apd.Decimal, precision, scale int) error

LimitDecimalWidth limits d's precision (total number of digits) and scale (number of digits after the decimal point).

func PGDisplayName Uses

func PGDisplayName(typ Type) string

PGDisplayName returns the Postgres display name for a given type.

func PGIOBuiltinPrefix Uses

func PGIOBuiltinPrefix(typ Type) string

PGIOBuiltinPrefix returns the string prefix to a type's IO functions. This is either the type's postgres display name or the type's postgres display name plus an underscore, depending on the type.

func ReNormalizeName Uses

func ReNormalizeName(name string) string

ReNormalizeName performs the same work as NormalizeName but when the string originates from the database. We define a different function so as to be able to track usage of this function (cf. #8200).

func Serialize Uses

func Serialize(n NodeFormatter) string

Serialize pretty prints a node to a string using FmtParsable; it is appropriate when we store expressions into strings that are later parsed back into expressions.

func SimilarEscape Uses

func SimilarEscape(pattern string) string

SimilarEscape converts a SQL:2008 regexp pattern to POSIX style, so it can be used by our regexp engine.

func StmtDebugString Uses

func StmtDebugString(stmt Statement) string

StmtDebugString generates multi-line debug strings in Go format for the expressions that are part of the given statement.

func ValidateRestartCheckpoint Uses

func ValidateRestartCheckpoint(savepoint string) error

ValidateRestartCheckpoint checks that a checkpoint name is our magic restart value. We accept everything with the desired prefix because at least the C++ libpqxx appends sequence numbers to the savepoint name specified by the user.

func WalkExprConst Uses

func WalkExprConst(v Visitor, expr Expr)

WalkExprConst is a variant of WalkExpr for visitors that do not modify the expression.

type AggregateFunc Uses

type AggregateFunc interface {
    // Add accumulates the passed datum into the AggregateFunc.
    Add(context.Context, Datum) error

    // Result returns the current value of the accumulation. This value
    // will be a deep copy of any AggregateFunc internal state, so that
    // it will not be mutated by additional calls to Add.
    Result() (Datum, error)

    // Close closes out the AggregateFunc and allows it to release any memory it
    // requested during aggregation, and must be called upon completion of the
    // aggregation.
    Close(context.Context)
}

AggregateFunc accumulates the result of a function of a Datum.

func NewIdentAggregate Uses

func NewIdentAggregate(*EvalContext) AggregateFunc

NewIdentAggregate returns an identAggregate (see comment on struct).

type AliasClause Uses

type AliasClause struct {
    Alias Name
    Cols  NameList
}

AliasClause represents an alias, optionally with a column list: "AS name" or "AS name(col1, col2)".

func (AliasClause) Format Uses

func (a AliasClause) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type AliasedTableExpr Uses

type AliasedTableExpr struct {
    Expr       TableExpr
    Hints      *IndexHints
    Ordinality bool
    As         AliasClause
}

AliasedTableExpr represents a table expression coupled with an optional alias.

func (*AliasedTableExpr) Format Uses

func (node *AliasedTableExpr) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*AliasedTableExpr) String Uses

func (node *AliasedTableExpr) String() string

type AllColumnsSelector Uses

type AllColumnsSelector struct {
    TableName
}

AllColumnsSelector corresponds to a selection of all columns in a table when used in a SELECT clause. (e.g. `table.*`)

func (*AllColumnsSelector) Eval Uses

func (expr *AllColumnsSelector) Eval(ctx *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*AllColumnsSelector) Format Uses

func (a *AllColumnsSelector) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*AllColumnsSelector) NormalizeVarName Uses

func (a *AllColumnsSelector) NormalizeVarName() (VarName, error)

NormalizeVarName is a no-op for AllColumnsSelector (already normalized)

func (*AllColumnsSelector) ResolvedType Uses

func (*AllColumnsSelector) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*AllColumnsSelector) String Uses

func (a *AllColumnsSelector) String() string

func (*AllColumnsSelector) TypeCheck Uses

func (expr *AllColumnsSelector) TypeCheck(_ *SemaContext, desired Type) (TypedExpr, error)

TypeCheck implements the Expr interface.

func (*AllColumnsSelector) Variable Uses

func (a *AllColumnsSelector) Variable()

Variable implements the VariableExpr interface. Although, the AllColumnsSelector ought to be replaced to an IndexedVar before the points the VariableExpr interface is used.

func (*AllColumnsSelector) Walk Uses

func (expr *AllColumnsSelector) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type AllTablesSelector Uses

type AllTablesSelector struct {
    Database Name
}

AllTablesSelector corresponds to a selection of all tables in a database, e.g. when used with GRANT.

func (*AllTablesSelector) Format Uses

func (at *AllTablesSelector) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*AllTablesSelector) NormalizeTablePattern Uses

func (at *AllTablesSelector) NormalizeTablePattern() (TablePattern, error)

NormalizeTablePattern implements the TablePattern interface.

func (*AllTablesSelector) QualifyWithDatabase Uses

func (at *AllTablesSelector) QualifyWithDatabase(database string) error

QualifyWithDatabase adds an indirection for the database, if it's missing. It transforms: * -> database.*

func (*AllTablesSelector) String Uses

func (at *AllTablesSelector) String() string

type AlterTable Uses

type AlterTable struct {
    IfExists bool
    Table    NormalizableTableName
    Cmds     AlterTableCmds
}

AlterTable represents an ALTER TABLE statement.

func (*AlterTable) Format Uses

func (node *AlterTable) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*AlterTable) StatementTag Uses

func (*AlterTable) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*AlterTable) StatementType Uses

func (*AlterTable) StatementType() StatementType

StatementType implements the Statement interface.

func (*AlterTable) String Uses

func (n *AlterTable) String() string

type AlterTableAddColumn Uses

type AlterTableAddColumn struct {
    IfNotExists bool
    ColumnDef   *ColumnTableDef
    // contains filtered or unexported fields
}

AlterTableAddColumn represents an ADD COLUMN command.

func (*AlterTableAddColumn) Format Uses

func (node *AlterTableAddColumn) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*AlterTableAddColumn) String Uses

func (n *AlterTableAddColumn) String() string

type AlterTableAddConstraint Uses

type AlterTableAddConstraint struct {
    ConstraintDef      ConstraintTableDef
    ValidationBehavior ValidationBehavior
}

AlterTableAddConstraint represents an ADD CONSTRAINT command.

func (*AlterTableAddConstraint) Format Uses

func (node *AlterTableAddConstraint) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*AlterTableAddConstraint) String Uses

func (n *AlterTableAddConstraint) String() string

type AlterTableCmd Uses

type AlterTableCmd interface {
    NodeFormatter
    // contains filtered or unexported methods
}

AlterTableCmd represents a table modification operation.

type AlterTableCmds Uses

type AlterTableCmds []AlterTableCmd

AlterTableCmds represents a list of table alterations.

func (AlterTableCmds) Format Uses

func (node AlterTableCmds) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (AlterTableCmds) String Uses

func (n AlterTableCmds) String() string

type AlterTableDropColumn Uses

type AlterTableDropColumn struct {
    IfExists     bool
    Column       Name
    DropBehavior DropBehavior
    // contains filtered or unexported fields
}

AlterTableDropColumn represents a DROP COLUMN command.

func (*AlterTableDropColumn) Format Uses

func (node *AlterTableDropColumn) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*AlterTableDropColumn) String Uses

func (n *AlterTableDropColumn) String() string

type AlterTableDropConstraint Uses

type AlterTableDropConstraint struct {
    IfExists     bool
    Constraint   Name
    DropBehavior DropBehavior
}

AlterTableDropConstraint represents a DROP CONSTRAINT command.

func (*AlterTableDropConstraint) Format Uses

func (node *AlterTableDropConstraint) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*AlterTableDropConstraint) String Uses

func (n *AlterTableDropConstraint) String() string

type AlterTableDropNotNull Uses

type AlterTableDropNotNull struct {
    Column Name
    // contains filtered or unexported fields
}

AlterTableDropNotNull represents an ALTER COLUMN DROP NOT NULL command.

func (*AlterTableDropNotNull) Format Uses

func (node *AlterTableDropNotNull) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*AlterTableDropNotNull) GetColumn Uses

func (node *AlterTableDropNotNull) GetColumn() Name

GetColumn implements the ColumnMutationCmd interface.

func (*AlterTableDropNotNull) String Uses

func (n *AlterTableDropNotNull) String() string

type AlterTableSetDefault Uses

type AlterTableSetDefault struct {
    Column  Name
    Default Expr
    // contains filtered or unexported fields
}

AlterTableSetDefault represents an ALTER COLUMN SET DEFAULT or DROP DEFAULT command.

func (*AlterTableSetDefault) Format Uses

func (node *AlterTableSetDefault) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*AlterTableSetDefault) GetColumn Uses

func (node *AlterTableSetDefault) GetColumn() Name

GetColumn implements the ColumnMutationCmd interface.

func (*AlterTableSetDefault) String Uses

func (n *AlterTableSetDefault) String() string

type AlterTableValidateConstraint Uses

type AlterTableValidateConstraint struct {
    Constraint Name
}

AlterTableValidateConstraint represents a VALIDATE CONSTRAINT command.

func (*AlterTableValidateConstraint) Format Uses

func (node *AlterTableValidateConstraint) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type AndExpr Uses

type AndExpr struct {
    Left, Right Expr
    // contains filtered or unexported fields
}

AndExpr represents an AND expression.

func NewTypedAndExpr Uses

func NewTypedAndExpr(left, right TypedExpr) *AndExpr

NewTypedAndExpr returns a new AndExpr that is verified to be well-typed.

func (*AndExpr) Eval Uses

func (expr *AndExpr) Eval(ctx *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*AndExpr) Format Uses

func (node *AndExpr) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (AndExpr) ResolvedType Uses

func (ta AndExpr) ResolvedType() Type

func (*AndExpr) String Uses

func (node *AndExpr) String() string

func (*AndExpr) TypeCheck Uses

func (expr *AndExpr) TypeCheck(ctx *SemaContext, desired Type) (TypedExpr, error)

TypeCheck implements the Expr interface.

func (*AndExpr) TypedLeft Uses

func (node *AndExpr) TypedLeft() TypedExpr

TypedLeft returns the AndExpr's left expression as a TypedExpr.

func (*AndExpr) TypedRight Uses

func (node *AndExpr) TypedRight() TypedExpr

TypedRight returns the AndExpr's right expression as a TypedExpr.

func (*AndExpr) Walk Uses

func (expr *AndExpr) Walk(v Visitor) Expr

Walk implements the Expr interface.

type AnnotateTypeExpr Uses

type AnnotateTypeExpr struct {
    Expr Expr
    Type CastTargetType
    // contains filtered or unexported fields
}

AnnotateTypeExpr represents a ANNOTATE_TYPE(expr, type) expression.

func (*AnnotateTypeExpr) Format Uses

func (node *AnnotateTypeExpr) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*AnnotateTypeExpr) String Uses

func (node *AnnotateTypeExpr) String() string

func (*AnnotateTypeExpr) TypeCheck Uses

func (expr *AnnotateTypeExpr) TypeCheck(ctx *SemaContext, desired Type) (TypedExpr, error)

TypeCheck implements the Expr interface.

func (*AnnotateTypeExpr) TypedInnerExpr Uses

func (node *AnnotateTypeExpr) TypedInnerExpr() TypedExpr

TypedInnerExpr returns the AnnotateTypeExpr's inner expression as a TypedExpr.

func (*AnnotateTypeExpr) Walk Uses

func (expr *AnnotateTypeExpr) Walk(v Visitor) Expr

Walk implements the Expr interface.

type ArgTypes Uses

type ArgTypes []struct {
    Name string
    Typ  Type
}

ArgTypes is very similar to ArgTypes except it allows keeping a string name for each argument as well and using those when printing the human-readable signature.

func (ArgTypes) Length Uses

func (a ArgTypes) Length() int

Length implements the typeList interface.

func (ArgTypes) String Uses

func (a ArgTypes) String() string

func (ArgTypes) Types Uses

func (a ArgTypes) Types() []Type

Types implements the typeList interface.

type Array Uses

type Array struct {
    Exprs Exprs
    // contains filtered or unexported fields
}

Array represents an array constructor.

func (*Array) Eval Uses

func (t *Array) Eval(ctx *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*Array) Format Uses

func (node *Array) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (Array) ResolvedType Uses

func (ta Array) ResolvedType() Type

func (*Array) String Uses

func (node *Array) String() string

func (*Array) TypeCheck Uses

func (expr *Array) TypeCheck(ctx *SemaContext, desired Type) (TypedExpr, error)

TypeCheck implements the Expr interface.

func (*Array) Walk Uses

func (expr *Array) Walk(v Visitor) Expr

Walk implements the Expr interface.

type ArrayColType Uses

type ArrayColType struct {
    Name string
    // ParamTyp is the type of the elements in this array.
    ParamType   ColumnType
    BoundsExprs Exprs
}

ArrayColType represents an ARRAY column type.

func (*ArrayColType) Format Uses

func (node *ArrayColType) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*ArrayColType) String Uses

func (node *ArrayColType) String() string

type ArrayFlatten Uses

type ArrayFlatten struct {
    Subquery Expr
    // contains filtered or unexported fields
}

ArrayFlatten represents a subquery array constructor.

func (*ArrayFlatten) Eval Uses

func (t *ArrayFlatten) Eval(ctx *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*ArrayFlatten) Format Uses

func (node *ArrayFlatten) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (ArrayFlatten) ResolvedType Uses

func (ta ArrayFlatten) ResolvedType() Type

func (*ArrayFlatten) String Uses

func (node *ArrayFlatten) String() string

func (*ArrayFlatten) TypeCheck Uses

func (expr *ArrayFlatten) TypeCheck(ctx *SemaContext, desired Type) (TypedExpr, error)

TypeCheck implements the Expr interface.

func (*ArrayFlatten) Walk Uses

func (expr *ArrayFlatten) Walk(v Visitor) Expr

Walk implements the Expr interface.

type ArraySubscript Uses

type ArraySubscript struct {
    Begin Expr
    End   Expr
    Slice bool
}

ArraySubscript corresponds to the syntax `<name>[ ... ]`.

func (*ArraySubscript) Format Uses

func (a *ArraySubscript) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type ArraySubscripts Uses

type ArraySubscripts []*ArraySubscript

ArraySubscripts represents a sequence of one or more array subscripts.

func (ArraySubscripts) Format Uses

func (a ArraySubscripts) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type AsOfClause Uses

type AsOfClause struct {
    Expr Expr
}

AsOfClause represents an as of time.

func (AsOfClause) Format Uses

func (a AsOfClause) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type Backup Uses

type Backup struct {
    Targets         TargetList
    To              Expr
    IncrementalFrom Exprs
    AsOf            AsOfClause
    Options         KVOptions
}

Backup represents a BACKUP statement.

func (*Backup) Format Uses

func (node *Backup) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*Backup) StatementTag Uses

func (*Backup) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Backup) StatementType Uses

func (*Backup) StatementType() StatementType

StatementType implements the Statement interface.

func (*Backup) String Uses

func (n *Backup) String() string

type BeginTransaction Uses

type BeginTransaction struct {
    Modes TransactionModes
}

BeginTransaction represents a BEGIN statement

func (*BeginTransaction) Format Uses

func (node *BeginTransaction) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*BeginTransaction) StatementTag Uses

func (*BeginTransaction) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*BeginTransaction) StatementType Uses

func (*BeginTransaction) StatementType() StatementType

StatementType implements the Statement interface.

func (*BeginTransaction) String Uses

func (n *BeginTransaction) String() string

type BinOp Uses

type BinOp struct {
    LeftType   Type
    RightType  Type
    ReturnType Type
    // contains filtered or unexported fields
}

BinOp is a binary operator.

type BinaryExpr Uses

type BinaryExpr struct {
    Operator    BinaryOperator
    Left, Right Expr
    // contains filtered or unexported fields
}

BinaryExpr represents a binary value expression.

func (*BinaryExpr) Eval Uses

func (expr *BinaryExpr) Eval(ctx *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*BinaryExpr) Format Uses

func (node *BinaryExpr) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (BinaryExpr) ResolvedType Uses

func (ta BinaryExpr) ResolvedType() Type

func (*BinaryExpr) String Uses

func (node *BinaryExpr) String() string

func (*BinaryExpr) TypeCheck Uses

func (expr *BinaryExpr) TypeCheck(ctx *SemaContext, desired Type) (TypedExpr, error)

TypeCheck implements the Expr interface.

func (*BinaryExpr) TypedLeft Uses

func (node *BinaryExpr) TypedLeft() TypedExpr

TypedLeft returns the BinaryExpr's left expression as a TypedExpr.

func (*BinaryExpr) TypedRight Uses

func (node *BinaryExpr) TypedRight() TypedExpr

TypedRight returns the BinaryExpr's right expression as a TypedExpr.

func (*BinaryExpr) Walk Uses

func (expr *BinaryExpr) Walk(v Visitor) Expr

Walk implements the Expr interface.

type BinaryOperator Uses

type BinaryOperator int

BinaryOperator represents a binary operator.

const (
    Bitand BinaryOperator = iota
    Bitor
    Bitxor
    Plus
    Minus
    Mult
    Div
    FloorDiv
    Mod
    Pow
    Concat
    LShift
    RShift
)

BinaryExpr.Operator

func (BinaryOperator) String Uses

func (i BinaryOperator) String() string

type BoolColType Uses

type BoolColType struct {
    Name string
}

BoolColType represents a BOOLEAN type.

func (*BoolColType) Format Uses

func (node *BoolColType) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*BoolColType) String Uses

func (node *BoolColType) String() string

type Builtin Uses

type Builtin struct {
    Types      typeList
    ReturnType returnTyper

    // Info is a description of the function, which is surfaced on the CockroachDB
    // docs site on the "Functions and Operators" page. Descriptions typically use
    // third-person with the function as an implicit subject (e.g. "Calculates
    // infinity"), but should focus more on ease of understanding so other structures
    // might be more appropriate.
    Info string

    AggregateFunc func([]Type, *EvalContext) AggregateFunc
    WindowFunc    func([]Type, *EvalContext) WindowFunc
    // contains filtered or unexported fields
}

Builtin is a built-in function.

func (Builtin) Category Uses

func (b Builtin) Category() string

Category is used to categorize a function (for documentation purposes).

func (Builtin) Class Uses

func (b Builtin) Class() FunctionClass

Class returns the FunctionClass of this builtin.

func (Builtin) DistSQLBlacklist Uses

func (b Builtin) DistSQLBlacklist() bool

DistSQLBlacklist returns true if the builtin is not supported by DistSQL. See distsqlBlacklist.

func (Builtin) FixedReturnType Uses

func (b Builtin) FixedReturnType() Type

FixedReturnType returns a fixed type that the function returns, returning Any if the return type is based on the function's arguments.

func (Builtin) Fn Uses

func (b Builtin) Fn() func(*EvalContext, Datums) (Datum, error)

Fn returns the Go function which implements the builtin.

func (Builtin) Impure Uses

func (b Builtin) Impure() bool

Impure returns false if this builtin is a pure function of its inputs.

func (Builtin) Signature Uses

func (b Builtin) Signature() string

Signature returns a human-readable signature.

type BytesColType Uses

type BytesColType struct {
    Name string
}

BytesColType represents a BYTES or BLOB type.

func (*BytesColType) Format Uses

func (node *BytesColType) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*BytesColType) String Uses

func (node *BytesColType) String() string

type CancelJob Uses

type CancelJob struct {
    ID Expr
}

CancelJob represents a CANCEL JOB statement.

func (*CancelJob) Format Uses

func (node *CancelJob) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*CancelJob) StatementTag Uses

func (*CancelJob) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CancelJob) StatementType Uses

func (*CancelJob) StatementType() StatementType

StatementType implements the Statement interface.

func (*CancelJob) String Uses

func (n *CancelJob) String() string

type CancelQuery Uses

type CancelQuery struct {
    ID Expr
}

CancelQuery represents a CANCEL QUERY statement.

func (*CancelQuery) Format Uses

func (node *CancelQuery) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*CancelQuery) StatementTag Uses

func (*CancelQuery) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CancelQuery) StatementType Uses

func (*CancelQuery) StatementType() StatementType

StatementType implements the Statement interface.

func (*CancelQuery) String Uses

func (n *CancelQuery) String() string

type CaseExpr Uses

type CaseExpr struct {
    Expr  Expr
    Whens []*When
    Else  Expr
    // contains filtered or unexported fields
}

CaseExpr represents a CASE expression.

func (*CaseExpr) CopyNode Uses

func (expr *CaseExpr) CopyNode() *CaseExpr

CopyNode makes a copy of this Expr without recursing in any child Exprs.

func (*CaseExpr) Eval Uses

func (expr *CaseExpr) Eval(ctx *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*CaseExpr) Format Uses

func (node *CaseExpr) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (CaseExpr) ResolvedType Uses

func (ta CaseExpr) ResolvedType() Type

func (*CaseExpr) String Uses

func (node *CaseExpr) String() string

func (*CaseExpr) TypeCheck Uses

func (expr *CaseExpr) TypeCheck(ctx *SemaContext, desired Type) (TypedExpr, error)

TypeCheck implements the Expr interface.

func (*CaseExpr) Walk Uses

func (expr *CaseExpr) Walk(v Visitor) Expr

Walk implements the Expr interface.

type CastExpr Uses

type CastExpr struct {
    Expr Expr
    Type CastTargetType
    // contains filtered or unexported fields
}

CastExpr represents a CAST(expr AS type) expression.

func (*CastExpr) Eval Uses

func (expr *CastExpr) Eval(ctx *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*CastExpr) Format Uses

func (node *CastExpr) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (CastExpr) ResolvedType Uses

func (ta CastExpr) ResolvedType() Type

func (*CastExpr) String Uses

func (node *CastExpr) String() string

func (*CastExpr) TypeCheck Uses

func (expr *CastExpr) TypeCheck(ctx *SemaContext, _ Type) (TypedExpr, error)

TypeCheck implements the Expr interface.

func (*CastExpr) Walk Uses

func (expr *CastExpr) Walk(v Visitor) Expr

Walk implements the Expr interface.

type CastTargetType Uses

type CastTargetType interface {
    fmt.Stringer
    NodeFormatter
    // contains filtered or unexported methods
}

CastTargetType represents a type that is a valid cast target.

func ParseType Uses

func ParseType(sql string) (CastTargetType, error)

ParseType parses a column type.

type CheckConstraintTableDef Uses

type CheckConstraintTableDef struct {
    Name Name
    Expr Expr
}

CheckConstraintTableDef represents a check constraint within a CREATE TABLE statement.

func (*CheckConstraintTableDef) Format Uses

func (node *CheckConstraintTableDef) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type CmpOp Uses

type CmpOp struct {
    LeftType  Type
    RightType Type
    // contains filtered or unexported fields
}

CmpOp is a comparison operator.

type CoalesceExpr Uses

type CoalesceExpr struct {
    Name  string
    Exprs Exprs
    // contains filtered or unexported fields
}

CoalesceExpr represents a COALESCE or IFNULL expression.

func (*CoalesceExpr) CopyNode Uses

func (expr *CoalesceExpr) CopyNode() *CoalesceExpr

CopyNode makes a copy of this Expr without recursing in any child Exprs.

func (*CoalesceExpr) Eval Uses

func (expr *CoalesceExpr) Eval(ctx *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*CoalesceExpr) Format Uses

func (node *CoalesceExpr) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (CoalesceExpr) ResolvedType Uses

func (ta CoalesceExpr) ResolvedType() Type

func (*CoalesceExpr) String Uses

func (node *CoalesceExpr) String() string

func (*CoalesceExpr) TypeCheck Uses

func (expr *CoalesceExpr) TypeCheck(ctx *SemaContext, desired Type) (TypedExpr, error)

TypeCheck implements the Expr interface.

func (*CoalesceExpr) TypedExprAt Uses

func (node *CoalesceExpr) TypedExprAt(idx int) TypedExpr

TypedExprAt returns the expression at the specified index as a TypedExpr.

func (*CoalesceExpr) Walk Uses

func (expr *CoalesceExpr) Walk(v Visitor) Expr

Walk implements the Expr interface.

type CollateExpr Uses

type CollateExpr struct {
    Expr   Expr
    Locale string
    // contains filtered or unexported fields
}

CollateExpr represents an (expr COLLATE locale) expression.

func (*CollateExpr) Eval Uses

func (expr *CollateExpr) Eval(ctx *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*CollateExpr) Format Uses

func (node *CollateExpr) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (CollateExpr) ResolvedType Uses

func (ta CollateExpr) ResolvedType() Type

func (*CollateExpr) String Uses

func (node *CollateExpr) String() string

func (*CollateExpr) TypeCheck Uses

func (expr *CollateExpr) TypeCheck(ctx *SemaContext, desired Type) (TypedExpr, error)

TypeCheck implements the Expr interface.

func (*CollateExpr) Walk Uses

func (expr *CollateExpr) Walk(v Visitor) Expr

Walk implements the Expr interface.

type CollatedStringColType Uses

type CollatedStringColType struct {
    Name   string
    N      int
    Locale string
}

CollatedStringColType represents a STRING, CHAR or VARCHAR type with a collation locale.

func (*CollatedStringColType) Format Uses

func (node *CollatedStringColType) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*CollatedStringColType) String Uses

func (node *CollatedStringColType) String() string

type CollationEnvironment Uses

type CollationEnvironment struct {
    // contains filtered or unexported fields
}

CollationEnvironment stores the state needed by NewDCollatedString to construct collation keys efficiently.

type ColumnCheckConstraint Uses

type ColumnCheckConstraint struct {
    Expr Expr
}

ColumnCheckConstraint represents either a check on a column.

type ColumnCollation Uses

type ColumnCollation string

ColumnCollation represents a COLLATE clause for a column.

type ColumnDefault Uses

type ColumnDefault struct {
    Expr Expr
}

ColumnDefault represents a DEFAULT clause for a column.

type ColumnFKConstraint Uses

type ColumnFKConstraint struct {
    Table NormalizableTableName
    Col   Name // empty-string means use PK
}

ColumnFKConstraint represents a FK-constaint on a column.

type ColumnFamilyConstraint Uses

type ColumnFamilyConstraint struct {
    Family      Name
    Create      bool
    IfNotExists bool
}

ColumnFamilyConstraint represents FAMILY on a column.

type ColumnID Uses

type ColumnID uint32

ColumnID is a custom type for ColumnDescriptor IDs.

type ColumnItem Uses

type ColumnItem struct {
    // TableName holds the table prefix, if the name refers to a column.
    TableName TableName
    // ColumnName names the designated column.
    ColumnName Name
    // Selector defines which sub-part of the variable is being
    // accessed.
    Selector NameParts
}

ColumnItem corresponds to the name of a column or sub-item of a column in an expression.

func (*ColumnItem) Column Uses

func (c *ColumnItem) Column() string

Column retrieves the unqualified column name.

func (*ColumnItem) Eval Uses

func (expr *ColumnItem) Eval(ctx *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*ColumnItem) Format Uses

func (c *ColumnItem) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*ColumnItem) NormalizeVarName Uses

func (c *ColumnItem) NormalizeVarName() (VarName, error)

NormalizeVarName is a no-op for ColumnItem (already normalized)

func (*ColumnItem) ResolvedType Uses

func (c *ColumnItem) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*ColumnItem) String Uses

func (c *ColumnItem) String() string

func (*ColumnItem) TypeCheck Uses

func (expr *ColumnItem) TypeCheck(_ *SemaContext, desired Type) (TypedExpr, error)

TypeCheck implements the Expr interface. This function has a valid implementation only for testing within this package. During query execution, ColumnItems are replaced to IndexedVars prior to type checking.

func (*ColumnItem) Variable Uses

func (c *ColumnItem) Variable()

Variable implements the VariableExpr interface. Although, the ColumnItem ought to be replaced to an IndexedVar before the points the VariableExpr interface is used.

func (*ColumnItem) Walk Uses

func (expr *ColumnItem) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type ColumnMutationCmd Uses

type ColumnMutationCmd interface {
    AlterTableCmd
    GetColumn() Name
}

ColumnMutationCmd is the subset of AlterTableCmds that modify an existing column.

type ColumnQualification Uses

type ColumnQualification interface {
    // contains filtered or unexported methods
}

ColumnQualification represents a constraint on a column.

type ColumnTableDef Uses

type ColumnTableDef struct {
    Name     Name
    Type     ColumnType
    Nullable struct {
        Nullability    Nullability
        ConstraintName Name
    }
    PrimaryKey           bool
    Unique               bool
    UniqueConstraintName Name
    DefaultExpr          struct {
        Expr           Expr
        ConstraintName Name
    }
    CheckExprs []ColumnTableDefCheckExpr
    References struct {
        Table          NormalizableTableName
        Col            Name
        ConstraintName Name
    }
    Family struct {
        Name        Name
        Create      bool
        IfNotExists bool
    }
}

ColumnTableDef represents a column definition within a CREATE TABLE statement.

func (*ColumnTableDef) Format Uses

func (node *ColumnTableDef) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*ColumnTableDef) HasColumnFamily Uses

func (node *ColumnTableDef) HasColumnFamily() bool

HasColumnFamily returns if the ColumnTableDef has a column family.

func (*ColumnTableDef) HasDefaultExpr Uses

func (node *ColumnTableDef) HasDefaultExpr() bool

HasDefaultExpr returns if the ColumnTableDef has a default expression.

func (*ColumnTableDef) HasFKConstraint Uses

func (node *ColumnTableDef) HasFKConstraint() bool

HasFKConstraint returns if the ColumnTableDef has a foreign key constraint.

type ColumnTableDefCheckExpr Uses

type ColumnTableDefCheckExpr struct {
    Expr           Expr
    ConstraintName Name
}

ColumnTableDefCheckExpr represents a check constraint on a column definition within a CREATE TABLE statement.

type ColumnType Uses

type ColumnType interface {
    CastTargetType
    // contains filtered or unexported methods
}

ColumnType represents a type in a column definition.

func DatumTypeToColumnType Uses

func DatumTypeToColumnType(t Type) (ColumnType, error)

DatumTypeToColumnType produces a SQL column type equivalent to the given Datum type. Used to generate CastExpr nodes during normalization.

type CommitTransaction Uses

type CommitTransaction struct{}

CommitTransaction represents a COMMIT statement.

func (*CommitTransaction) Format Uses

func (node *CommitTransaction) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*CommitTransaction) StatementTag Uses

func (*CommitTransaction) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CommitTransaction) StatementType Uses

func (*CommitTransaction) StatementType() StatementType

StatementType implements the Statement interface.

func (*CommitTransaction) String Uses

func (n *CommitTransaction) String() string

type ComparisonExpr Uses

type ComparisonExpr struct {
    Operator    ComparisonOperator
    SubOperator ComparisonOperator // used for array operators (when Operator is Any, Some, or All)
    Left, Right Expr
    // contains filtered or unexported fields
}

ComparisonExpr represents a two-value comparison expression.

func NewTypedComparisonExpr Uses

func NewTypedComparisonExpr(op ComparisonOperator, left, right TypedExpr) *ComparisonExpr

NewTypedComparisonExpr returns a new ComparisonExpr that is verified to be well-typed.

func (*ComparisonExpr) Eval Uses

func (expr *ComparisonExpr) Eval(ctx *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*ComparisonExpr) Format Uses

func (node *ComparisonExpr) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*ComparisonExpr) IsMixedTypeComparison Uses

func (node *ComparisonExpr) IsMixedTypeComparison() bool

IsMixedTypeComparison returns true when the two sides of a comparison operator have different types.

func (ComparisonExpr) ResolvedType Uses

func (ta ComparisonExpr) ResolvedType() Type

func (*ComparisonExpr) String Uses

func (node *ComparisonExpr) String() string

func (*ComparisonExpr) TypeCheck Uses

func (expr *ComparisonExpr) TypeCheck(ctx *SemaContext, desired Type) (TypedExpr, error)

TypeCheck implements the Expr interface.

func (*ComparisonExpr) TypedLeft Uses

func (node *ComparisonExpr) TypedLeft() TypedExpr

TypedLeft returns the ComparisonExpr's left expression as a TypedExpr.

func (*ComparisonExpr) TypedRight Uses

func (node *ComparisonExpr) TypedRight() TypedExpr

TypedRight returns the ComparisonExpr's right expression as a TypedExpr.

func (*ComparisonExpr) Walk Uses

func (expr *ComparisonExpr) Walk(v Visitor) Expr

Walk implements the Expr interface.

type ComparisonOperator Uses

type ComparisonOperator int

ComparisonOperator represents a binary operator.

const (
    EQ  ComparisonOperator = iota
    LT
    GT
    LE
    GE
    NE
    In
    NotIn
    Like
    NotLike
    ILike
    NotILike
    SimilarTo
    NotSimilarTo
    RegMatch
    NotRegMatch
    RegIMatch
    NotRegIMatch
    IsDistinctFrom
    IsNotDistinctFrom
    Is
    IsNot

    // The following operators will always be used with an associated SubOperator.
    // If Go had algebraic data types they would be defined in a self-contained
    // manner like:
    //
    // Any(ComparisonOperator)
    // Some(ComparisonOperator)
    // ...
    //
    // where the internal ComparisonOperator qualifies the behavior of the primary
    // operator. Instead, a secondary ComparisonOperator is optionally included in
    // ComparisonExpr for the cases where these operators are the primary op.
    //
    // ComparisonOperator.hasSubOperator returns true for ops in this group.
    Any
    Some
    All
)

ComparisonExpr.Operator

func (ComparisonOperator) String Uses

func (i ComparisonOperator) String() string

type CompositeDatum Uses

type CompositeDatum interface {
    Datum
    // IsComposite returns true if this datum is not round-tripable in a key
    // encoding.
    IsComposite() bool
}

CompositeDatum is a Datum that may require composite encoding in indexes. Any Datum implementing this interface must also add itself to sqlbase/HasCompositeKeyEncoding.

type Constant Uses

type Constant interface {
    Expr
    // AvailableTypes returns the ordered set of types that the Constant is able to
    // be resolved into. The order of the type slice provides a notion of precedence,
    // with the first element in the ordering being the Constant's "natural type".
    AvailableTypes() []Type
    // ResolveAsType resolves the Constant as the Datum type specified, or returns an
    // error if the Constant could not be resolved as that type. The method should only
    // be passed a type returned from AvailableTypes and should never be called more than
    // once for a given Constant.
    ResolveAsType(*SemaContext, Type) (Datum, error)
}

Constant is an constant literal expression which may be resolved to more than one type.

type ConstraintTableDef Uses

type ConstraintTableDef interface {
    TableDef
    // contains filtered or unexported methods
}

ConstraintTableDef represents a constraint definition within a CREATE TABLE statement.

type ContainsWindowVisitor Uses

type ContainsWindowVisitor struct {
    // contains filtered or unexported fields
}

ContainsWindowVisitor checks if walked expressions contain window functions.

func (*ContainsWindowVisitor) ContainsWindowFunc Uses

func (v *ContainsWindowVisitor) ContainsWindowFunc(expr Expr) bool

ContainsWindowFunc determines if an Expr contains a window function.

func (*ContainsWindowVisitor) VisitPost Uses

func (*ContainsWindowVisitor) VisitPost(expr Expr) Expr

VisitPost satisfies the Visitor interface.

func (*ContainsWindowVisitor) VisitPre Uses

func (v *ContainsWindowVisitor) VisitPre(expr Expr) (recurse bool, newExpr Expr)

VisitPre satisfies the Visitor interface.

type CopyFrom Uses

type CopyFrom struct {
    Table   NormalizableTableName
    Columns UnresolvedNames
    Stdin   bool
}

CopyFrom represents a COPY FROM statement.

func (*CopyFrom) Format Uses

func (node *CopyFrom) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*CopyFrom) StatementTag Uses

func (*CopyFrom) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CopyFrom) StatementType Uses

func (*CopyFrom) StatementType() StatementType

StatementType implements the Statement interface.

func (*CopyFrom) String Uses

func (n *CopyFrom) String() string

type CreateDatabase Uses

type CreateDatabase struct {
    IfNotExists bool
    Name        Name
    Template    string
    Encoding    string
    Collate     string
    CType       string
}

CreateDatabase represents a CREATE DATABASE statement.

func (*CreateDatabase) Format Uses

func (node *CreateDatabase) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*CreateDatabase) StatementTag Uses

func (*CreateDatabase) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CreateDatabase) StatementType Uses

func (*CreateDatabase) StatementType() StatementType

StatementType implements the Statement interface.

func (*CreateDatabase) String Uses

func (n *CreateDatabase) String() string

type CreateIndex Uses

type CreateIndex struct {
    Name        Name
    Table       NormalizableTableName
    Unique      bool
    IfNotExists bool
    Columns     IndexElemList
    // Extra columns to be stored together with the indexed ones as an optimization
    // for improved reading performance.
    Storing    NameList
    Interleave *InterleaveDef
}

CreateIndex represents a CREATE INDEX statement.

func (*CreateIndex) Format Uses

func (node *CreateIndex) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*CreateIndex) StatementTag Uses

func (*CreateIndex) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CreateIndex) StatementType Uses

func (*CreateIndex) StatementType() StatementType

StatementType implements the Statement interface.

func (*CreateIndex) String Uses

func (n *CreateIndex) String() string

type CreateTable Uses

type CreateTable struct {
    IfNotExists   bool
    Table         NormalizableTableName
    Interleave    *InterleaveDef
    Defs          TableDefs
    AsSource      *Select
    AsColumnNames NameList // Only to be used in conjunction with AsSource
}

CreateTable represents a CREATE TABLE statement.

func (*CreateTable) As Uses

func (node *CreateTable) As() bool

As returns true if this table represents a CREATE TABLE ... AS statement, false otherwise.

func (*CreateTable) Format Uses

func (node *CreateTable) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*CreateTable) StatementTag Uses

func (n *CreateTable) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CreateTable) StatementType Uses

func (*CreateTable) StatementType() StatementType

StatementType implements the Statement interface.

func (*CreateTable) String Uses

func (n *CreateTable) String() string

type CreateUser Uses

type CreateUser struct {
    Name     Name
    Password *string // pointer so that empty and nil can be differentiated
}

CreateUser represents a CREATE USER statement.

func (*CreateUser) Format Uses

func (node *CreateUser) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*CreateUser) HasPassword Uses

func (node *CreateUser) HasPassword() bool

HasPassword returns if the CreateUser has a password.

func (*CreateUser) StatementTag Uses

func (*CreateUser) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CreateUser) StatementType Uses

func (*CreateUser) StatementType() StatementType

StatementType implements the Statement interface.

func (*CreateUser) String Uses

func (n *CreateUser) String() string

type CreateView Uses

type CreateView struct {
    Name        NormalizableTableName
    ColumnNames NameList
    AsSource    *Select
}

CreateView represents a CREATE VIEW statement.

func (*CreateView) Format Uses

func (node *CreateView) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*CreateView) StatementTag Uses

func (*CreateView) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CreateView) StatementType Uses

func (*CreateView) StatementType() StatementType

StatementType implements the Statement interface.

func (*CreateView) String Uses

func (n *CreateView) String() string

type DArray Uses

type DArray struct {
    ParamTyp Type
    Array    Datums
    // HasNulls is set to true if any of the datums within the array are null.
    // This is used in the binary array serialization format.
    HasNulls bool
}

DArray is the array Datum. Any Datum inserted into a DArray are treated as text during serialization.

func AsDArray Uses

func AsDArray(e Expr) (*DArray, bool)

AsDArray attempts to retrieve a *DArray from an Expr, returning a *DArray and a flag signifying whether the assertion was successful. The function should be used instead of direct type assertions wherever a *DArray wrapped by a *DOidWrapper is possible.

func MustBeDArray Uses

func MustBeDArray(e Expr) *DArray

MustBeDArray attempts to retrieve a *DArray from an Expr, panicking if the assertion fails.

func NewDArray Uses

func NewDArray(paramTyp Type) *DArray

NewDArray returns a DArray containing elements of the specified type.

func (*DArray) AmbiguousFormat Uses

func (*DArray) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DArray) Append Uses

func (d *DArray) Append(v Datum) error

Append appends a Datum to the array, whose parameterized type must be consistent with the type of the Datum.

func (*DArray) Compare Uses

func (d *DArray) Compare(ctx *EvalContext, other Datum) int

Compare implements the Datum interface.

func (*DArray) Eval Uses

func (t *DArray) Eval(_ *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*DArray) Format Uses

func (d *DArray) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*DArray) IsMax Uses

func (d *DArray) IsMax() bool

IsMax implements the Datum interface.

func (*DArray) IsMin Uses

func (d *DArray) IsMin() bool

IsMin implements the Datum interface.

func (*DArray) Len Uses

func (d *DArray) Len() int

Len returns the length of the Datum array.

func (*DArray) Next Uses

func (d *DArray) Next() (Datum, bool)

Next implements the Datum interface.

func (*DArray) Prev Uses

func (d *DArray) Prev() (Datum, bool)

Prev implements the Datum interface.

func (*DArray) ResolvedType Uses

func (d *DArray) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DArray) Size Uses

func (d *DArray) Size() uintptr

Size implements the Datum interface.

func (*DArray) String Uses

func (node *DArray) String() string

func (*DArray) TypeCheck Uses

func (d *DArray) TypeCheck(_ *SemaContext, _ Type) (TypedExpr, error)

TypeCheck implements the Expr interface. It is implemented as an idempotent identity function for Datum.

func (*DArray) Walk Uses

func (expr *DArray) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type DBool Uses

type DBool bool

DBool is the boolean Datum.

func GetBool Uses

func GetBool(d Datum) (DBool, error)

GetBool gets DBool or an error (also treats NULL as false, not an error).

func MakeDBool Uses

func MakeDBool(d DBool) *DBool

MakeDBool converts its argument to a *DBool, returning either DBoolTrue or DBoolFalse.

func ParseDBool Uses

func ParseDBool(s string) (*DBool, error)

ParseDBool parses and returns the *DBool Datum value represented by the provided string, or an error if parsing is unsuccessful.

func (*DBool) AmbiguousFormat Uses

func (*DBool) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DBool) Compare Uses

func (d *DBool) Compare(ctx *EvalContext, other Datum) int

Compare implements the Datum interface.

func (*DBool) Eval Uses

func (t *DBool) Eval(_ *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*DBool) Format Uses

func (d *DBool) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*DBool) IsMax Uses

func (d *DBool) IsMax() bool

IsMax implements the Datum interface.

func (*DBool) IsMin Uses

func (d *DBool) IsMin() bool

IsMin implements the Datum interface.

func (*DBool) Next Uses

func (*DBool) Next() (Datum, bool)

Next implements the Datum interface.

func (*DBool) Prev Uses

func (*DBool) Prev() (Datum, bool)

Prev implements the Datum interface.

func (*DBool) ResolvedType Uses

func (*DBool) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DBool) Size Uses

func (d *DBool) Size() uintptr

Size implements the Datum interface.

func (*DBool) String Uses

func (node *DBool) String() string

func (*DBool) TypeCheck Uses

func (d *DBool) TypeCheck(_ *SemaContext, _ Type) (TypedExpr, error)

TypeCheck implements the Expr interface. It is implemented as an idempotent identity function for Datum.

func (*DBool) Walk Uses

func (expr *DBool) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type DBytes Uses

type DBytes string

DBytes is the bytes Datum. The underlying type is a string because we want the immutability, but this may contain arbitrary bytes.

func NewDBytes Uses

func NewDBytes(d DBytes) *DBytes

NewDBytes is a helper routine to create a *DBytes initialized from its argument.

func (*DBytes) AmbiguousFormat Uses

func (*DBytes) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DBytes) Compare Uses

func (d *DBytes) Compare(ctx *EvalContext, other Datum) int

Compare implements the Datum interface.

func (*DBytes) Eval Uses

func (t *DBytes) Eval(_ *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*DBytes) Format Uses

func (d *DBytes) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*DBytes) IsMax Uses

func (*DBytes) IsMax() bool

IsMax implements the Datum interface.

func (*DBytes) IsMin Uses

func (d *DBytes) IsMin() bool

IsMin implements the Datum interface.

func (*DBytes) Next Uses

func (d *DBytes) Next() (Datum, bool)

Next implements the Datum interface.

func (*DBytes) Prev Uses

func (d *DBytes) Prev() (Datum, bool)

Prev implements the Datum interface.

func (*DBytes) ResolvedType Uses

func (*DBytes) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DBytes) Size Uses

func (d *DBytes) Size() uintptr

Size implements the Datum interface.

func (*DBytes) String Uses

func (node *DBytes) String() string

func (*DBytes) TypeCheck Uses

func (d *DBytes) TypeCheck(_ *SemaContext, _ Type) (TypedExpr, error)

TypeCheck implements the Expr interface. It is implemented as an idempotent identity function for Datum.

func (*DBytes) Walk Uses

func (expr *DBytes) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type DCollatedString Uses

type DCollatedString struct {
    Contents string
    Locale   string
    // Key is the collation key.
    Key []byte
}

DCollatedString is the Datum for strings with a locale. The struct members are intended to be immutable.

func NewDCollatedString Uses

func NewDCollatedString(
    contents string, locale string, env *CollationEnvironment,
) *DCollatedString

NewDCollatedString is a helper routine to create a *DCollatedString. Panics if locale is invalid. Not safe for concurrent use.

func (*DCollatedString) AmbiguousFormat Uses

func (*DCollatedString) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DCollatedString) Compare Uses

func (d *DCollatedString) Compare(ctx *EvalContext, other Datum) int

Compare implements the Datum interface.

func (*DCollatedString) Eval Uses

func (t *DCollatedString) Eval(_ *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*DCollatedString) Format Uses

func (d *DCollatedString) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*DCollatedString) IsComposite Uses

func (d *DCollatedString) IsComposite() bool

IsComposite implements the CompositeDatum interface.

func (*DCollatedString) IsMax Uses

func (*DCollatedString) IsMax() bool

IsMax implements the Datum interface.

func (*DCollatedString) IsMin Uses

func (d *DCollatedString) IsMin() bool

IsMin implements the Datum interface.

func (*DCollatedString) Next Uses

func (d *DCollatedString) Next() (Datum, bool)

Next implements the Datum interface.

func (*DCollatedString) Prev Uses

func (d *DCollatedString) Prev() (Datum, bool)

Prev implements the Datum interface.

func (*DCollatedString) ResolvedType Uses

func (d *DCollatedString) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DCollatedString) Size Uses

func (d *DCollatedString) Size() uintptr

Size implements the Datum interface.

func (*DCollatedString) String Uses

func (node *DCollatedString) String() string

func (*DCollatedString) TypeCheck Uses

func (d *DCollatedString) TypeCheck(_ *SemaContext, _ Type) (TypedExpr, error)

TypeCheck implements the Expr interface. It is implemented as an idempotent identity function for Datum.

func (*DCollatedString) Walk Uses

func (expr *DCollatedString) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type DDate Uses

type DDate int64

DDate is the date Datum represented as the number of days after the Unix epoch.

func NewDDate Uses

func NewDDate(d DDate) *DDate

NewDDate is a helper routine to create a *DDate initialized from its argument.

func NewDDateFromTime Uses

func NewDDateFromTime(t time.Time, loc *time.Location) *DDate

NewDDateFromTime constructs a *DDate from a time.Time in the provided time zone.

func ParseDDate Uses

func ParseDDate(s string, loc *time.Location) (*DDate, error)

ParseDDate parses and returns the *DDate Datum value represented by the provided string in the provided location, or an error if parsing is unsuccessful.

func (*DDate) AmbiguousFormat Uses

func (*DDate) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DDate) Compare Uses

func (d *DDate) Compare(ctx *EvalContext, other Datum) int

Compare implements the Datum interface.

func (*DDate) Eval Uses

func (t *DDate) Eval(_ *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*DDate) Format Uses

func (d *DDate) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*DDate) IsMax Uses

func (d *DDate) IsMax() bool

IsMax implements the Datum interface.

func (*DDate) IsMin Uses

func (d *DDate) IsMin() bool

IsMin implements the Datum interface.

func (*DDate) Next Uses

func (d *DDate) Next() (Datum, bool)

Next implements the Datum interface.

func (*DDate) Prev Uses

func (d *DDate) Prev() (Datum, bool)

Prev implements the Datum interface.

func (*DDate) ResolvedType Uses

func (*DDate) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DDate) Size Uses

func (d *DDate) Size() uintptr

Size implements the Datum interface.

func (*DDate) String Uses

func (node *DDate) String() string

func (*DDate) TypeCheck Uses

func (d *DDate) TypeCheck(_ *SemaContext, _ Type) (TypedExpr, error)

TypeCheck implements the Expr interface. It is implemented as an idempotent identity function for Datum.

func (*DDate) Walk Uses

func (expr *DDate) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type DDecimal Uses

type DDecimal struct {
    apd.Decimal
}

DDecimal is the decimal Datum.

var DecimalOne DDecimal

DecimalOne represents the constant 1 as DECIMAL.

func ParseDDecimal Uses

func ParseDDecimal(s string) (*DDecimal, error)

ParseDDecimal parses and returns the *DDecimal Datum value represented by the provided string, or an error if parsing is unsuccessful.

func TimestampToDecimal Uses

func TimestampToDecimal(ts hlc.Timestamp) *DDecimal

TimestampToDecimal converts the logical timestamp into a decimal value with the number of nanoseconds in the integer part and the logical counter in the decimal part.

func (*DDecimal) AmbiguousFormat Uses

func (*DDecimal) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DDecimal) Compare Uses

func (d *DDecimal) Compare(ctx *EvalContext, other Datum) int

Compare implements the Datum interface.

func (*DDecimal) Eval Uses

func (t *DDecimal) Eval(_ *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*DDecimal) Format Uses

func (d *DDecimal) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*DDecimal) IsComposite Uses

func (d *DDecimal) IsComposite() bool

IsComposite implements the CompositeDatum interface.

func (*DDecimal) IsMax Uses

func (*DDecimal) IsMax() bool

IsMax implements the Datum interface.

func (*DDecimal) IsMin Uses

func (*DDecimal) IsMin() bool

IsMin implements the Datum interface.

func (*DDecimal) Next Uses

func (d *DDecimal) Next() (Datum, bool)

Next implements the Datum interface.

func (*DDecimal) Prev Uses

func (d *DDecimal) Prev() (Datum, bool)

Prev implements the Datum interface.

func (*DDecimal) ResolvedType Uses

func (*DDecimal) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DDecimal) SetString Uses

func (d *DDecimal) SetString(s string) error

SetString sets d to s. Any non-standard NaN values are converted to a normal NaN.

func (*DDecimal) Size Uses

func (d *DDecimal) Size() uintptr

Size implements the Datum interface.

func (*DDecimal) String Uses

func (node *DDecimal) String() string

func (*DDecimal) TypeCheck Uses

func (d *DDecimal) TypeCheck(_ *SemaContext, _ Type) (TypedExpr, error)

TypeCheck implements the Expr interface. It is implemented as an idempotent identity function for Datum.

func (*DDecimal) Walk Uses

func (expr *DDecimal) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type DFloat Uses

type DFloat float64

DFloat is the float Datum.

func NewDFloat Uses

func NewDFloat(d DFloat) *DFloat

NewDFloat is a helper routine to create a *DFloat initialized from its argument.

func ParseDFloat Uses

func ParseDFloat(s string) (*DFloat, error)

ParseDFloat parses and returns the *DFloat Datum value represented by the provided string, or an error if parsing is unsuccessful.

func (*DFloat) AmbiguousFormat Uses

func (*DFloat) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DFloat) Compare Uses

func (d *DFloat) Compare(ctx *EvalContext, other Datum) int

Compare implements the Datum interface.

func (*DFloat) Eval Uses

func (t *DFloat) Eval(_ *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*DFloat) Format Uses

func (d *DFloat) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*DFloat) IsComposite Uses

func (d *DFloat) IsComposite() bool

IsComposite implements the CompositeDatum interface.

func (*DFloat) IsMax Uses

func (d *DFloat) IsMax() bool

IsMax implements the Datum interface.

func (*DFloat) IsMin Uses

func (d *DFloat) IsMin() bool

IsMin implements the Datum interface.

func (*DFloat) Next Uses

func (d *DFloat) Next() (Datum, bool)

Next implements the Datum interface.

func (*DFloat) Prev Uses

func (d *DFloat) Prev() (Datum, bool)

Prev implements the Datum interface.

func (*DFloat) ResolvedType Uses

func (*DFloat) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DFloat) Size Uses

func (d *DFloat) Size() uintptr

Size implements the Datum interface.

func (*DFloat) String Uses

func (node *DFloat) String() string

func (*DFloat) TypeCheck Uses

func (d *DFloat) TypeCheck(_ *SemaContext, _ Type) (TypedExpr, error)

TypeCheck implements the Expr interface. It is implemented as an idempotent identity function for Datum.

func (*DFloat) Walk Uses

func (expr *DFloat) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type DInt Uses

type DInt int64

DInt is the int Datum.

func AsDInt Uses

func AsDInt(e Expr) (DInt, bool)

AsDInt attempts to retrieve a DInt from an Expr, returning a DInt and a flag signifying whether the assertion was successful. The function should be used instead of direct type assertions wherever a *DInt wrapped by a *DOidWrapper is possible.

func GenerateUniqueInt Uses

func GenerateUniqueInt(nodeID roachpb.NodeID) DInt

GenerateUniqueInt creates a unique int composed of the current time at a 10-microsecond granularity and the node-id. The node-id is stored in the lower 15 bits of the returned value and the timestamp is stored in the upper 48 bits. The top-bit is left empty so that negative values are not returned. The 48-bit timestamp field provides for 89 years of timestamps. We use a custom epoch (Jan 1, 2015) in order to utilize the entire timestamp range.

Note that GenerateUniqueInt() imposes a limit on node IDs while generateUniqueBytes() does not.

TODO(pmattis): Do we have to worry about persisting the milliseconds value periodically to avoid the clock ever going backwards (e.g. due to NTP adjustment)?

func MustBeDInt Uses

func MustBeDInt(e Expr) DInt

MustBeDInt attempts to retrieve a DInt from an Expr, panicking if the assertion fails.

func NewDInt Uses

func NewDInt(d DInt) *DInt

NewDInt is a helper routine to create a *DInt initialized from its argument.

func ParseDInt Uses

func ParseDInt(s string) (*DInt, error)

ParseDInt parses and returns the *DInt Datum value represented by the provided string, or an error if parsing is unsuccessful.

func (*DInt) AmbiguousFormat Uses

func (*DInt) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DInt) Compare Uses

func (d *DInt) Compare(ctx *EvalContext, other Datum) int

Compare implements the Datum interface.

func (*DInt) Eval Uses

func (t *DInt) Eval(_ *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*DInt) Format Uses

func (d *DInt) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*DInt) IsMax Uses

func (d *DInt) IsMax() bool

IsMax implements the Datum interface.

func (*DInt) IsMin Uses

func (d *DInt) IsMin() bool

IsMin implements the Datum interface.

func (*DInt) Next Uses

func (d *DInt) Next() (Datum, bool)

Next implements the Datum interface.

func (*DInt) Prev Uses

func (d *DInt) Prev() (Datum, bool)

Prev implements the Datum interface.

func (*DInt) ResolvedType Uses

func (*DInt) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DInt) Size Uses

func (d *DInt) Size() uintptr

Size implements the Datum interface.

func (*DInt) String Uses

func (node *DInt) String() string

func (*DInt) TypeCheck Uses

func (d *DInt) TypeCheck(_ *SemaContext, _ Type) (TypedExpr, error)

TypeCheck implements the Expr interface. It is implemented as an idempotent identity function for Datum.

func (*DInt) Walk Uses

func (expr *DInt) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type DInterval Uses

type DInterval struct {
    duration.Duration
}

DInterval is the interval Datum.

func ParseDInterval Uses

func ParseDInterval(s string) (*DInterval, error)

ParseDInterval parses and returns the *DInterval Datum value represented by the provided string, or an error if parsing is unsuccessful.

func ParseDIntervalWithField Uses

func ParseDIntervalWithField(s string, field durationField) (*DInterval, error)

ParseDIntervalWithField is like ParseDInterval, but it also takes a DurationField that both specifies the units for unitless, numeric intervals and also specifies the precision of the interval. Any precision in the input interval that's higher than the DurationField value will be truncated downward.

func (*DInterval) AmbiguousFormat Uses

func (*DInterval) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DInterval) Compare Uses

func (d *DInterval) Compare(ctx *EvalContext, other Datum) int

Compare implements the Datum interface.

func (*DInterval) Eval Uses

func (t *DInterval) Eval(_ *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*DInterval) Format Uses

func (d *DInterval) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*DInterval) IsMax Uses

func (d *DInterval) IsMax() bool

IsMax implements the Datum interface.

func (*DInterval) IsMin Uses

func (d *DInterval) IsMin() bool

IsMin implements the Datum interface.

func (*DInterval) Next Uses

func (d *DInterval) Next() (Datum, bool)

Next implements the Datum interface.

func (*DInterval) Prev Uses

func (d *DInterval) Prev() (Datum, bool)

Prev implements the Datum interface.

func (*DInterval) ResolvedType Uses

func (*DInterval) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DInterval) Size Uses

func (d *DInterval) Size() uintptr

Size implements the Datum interface.

func (*DInterval) String Uses

func (node *DInterval) String() string

func (*DInterval) TypeCheck Uses

func (d *DInterval) TypeCheck(_ *SemaContext, _ Type) (TypedExpr, error)

TypeCheck implements the Expr interface. It is implemented as an idempotent identity function for Datum.

func (*DInterval) ValueAsString Uses

func (d *DInterval) ValueAsString() string

ValueAsString returns the interval as a string (e.g. "1h2m").

func (*DInterval) Walk Uses

func (expr *DInterval) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type DOid Uses

type DOid struct {
    // A DOid embeds a DInt, the underlying integer OID for this OID datum.
    DInt
    // contains filtered or unexported fields
}

DOid is the Postgres OID datum. It can represent either an OID type or any of the reg* types, such as regproc or regclass.

func MakeDOid Uses

func MakeDOid(d DInt) DOid

MakeDOid is a helper routine to create a DOid initialized from a DInt.

func NewDOid Uses

func NewDOid(d DInt) *DOid

NewDOid is a helper routine to create a *DOid initialized from a DInt.

func (*DOid) AmbiguousFormat Uses

func (*DOid) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DOid) AsRegProc Uses

func (d *DOid) AsRegProc(name string) *DOid

AsRegProc changes the input DOid into a regproc with the given name and returns it.

func (*DOid) Compare Uses

func (d *DOid) Compare(ctx *EvalContext, other Datum) int

Compare implements the Datum interface.

func (*DOid) Eval Uses

func (t *DOid) Eval(_ *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*DOid) Format Uses

func (d *DOid) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the Datum interface.

func (*DOid) IsMax Uses

func (d *DOid) IsMax() bool

IsMax implements the Datum interface.

func (*DOid) IsMin Uses

func (d *DOid) IsMin() bool

IsMin implements the Datum interface.

func (*DOid) Next Uses

func (d *DOid) Next() (Datum, bool)

Next implements the Datum interface.

func (*DOid) Prev Uses

func (d *DOid) Prev() (Datum, bool)

Prev implements the Datum interface.

func (*DOid) ResolvedType Uses

func (d *DOid) ResolvedType() Type

ResolvedType implements the Datum interface.

func (*DOid) Size Uses

func (d *DOid) Size() uintptr

Size implements the Datum interface.

func (*DOid) String Uses

func (node *DOid) String() string

func (*DOid) TypeCheck Uses

func (d *DOid) TypeCheck(_ *SemaContext, _ Type) (TypedExpr, error)

TypeCheck implements the Expr interface. It is implemented as an idempotent identity function for Datum.

func (*DOid) Walk Uses

func (expr *DOid) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type DOidWrapper Uses

type DOidWrapper struct {
    Wrapped Datum
    Oid     oid.Oid
}

DOidWrapper is a Datum implementation which is a wrapper around a Datum, allowing custom Oid values to be attached to the Datum and its Type (see tOidWrapper). The reason the Datum type was introduced was to permit the introduction of Datum types with new Object IDs while maintaining identical behavior to current Datum types. Specifically, it obviates the need to: - define a new parser.Datum type. - define a new parser.Type type. - support operations and functions for the new Type. - support mixed-type operations between the new Type and the old Type.

Instead, DOidWrapper allows a standard Datum to be wrapped with a new Oid. This approach provides two major advantages: - performance of the existing Datum types are not affected because they

do not need to have custom oid.Oids added to their structure.

- the introduction of new Datum aliases is straightforward and does not require

additions to typing rules or type-dependent evaluation behavior.

Types that currently benefit from DOidWrapper are: - DName => DOidWrapper(*DString, oid.T_name)

func (*DOidWrapper) AmbiguousFormat Uses

func (d *DOidWrapper) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DOidWrapper) Compare Uses

func (d *DOidWrapper) Compare(ctx *EvalContext, other Datum) int

Compare implements the Datum interface.

func (*DOidWrapper) Eval Uses

func (t *DOidWrapper) Eval(_ *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*DOidWrapper) Format Uses

func (d *DOidWrapper) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*DOidWrapper) IsMax Uses

func (d *DOidWrapper) IsMax() bool

IsMax implements the Datum interface.

func (*DOidWrapper) IsMin Uses

func (d *DOidWrapper) IsMin() bool

IsMin implements the Datum interface.

func (*DOidWrapper) Next Uses

func (d *DOidWrapper) Next() (Datum, bool)

Next implements the Datum interface.

func (*DOidWrapper) Prev Uses

func (d *DOidWrapper) Prev() (Datum, bool)

Prev implements the Datum interface.

func (*DOidWrapper) ResolvedType Uses

func (d *DOidWrapper) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DOidWrapper) Size Uses

func (d *DOidWrapper) Size() uintptr

Size implements the Datum interface.

func (*DOidWrapper) String Uses

func (node *DOidWrapper) String() string

func (*DOidWrapper) TypeCheck Uses

func (d *DOidWrapper) TypeCheck(_ *SemaContext, _ Type) (TypedExpr, error)

TypeCheck implements the Expr interface. It is implemented as an idempotent identity function for Datum.

func (*DOidWrapper) Walk Uses

func (expr *DOidWrapper) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type DString Uses

type DString string

DString is the string Datum.

func AsDString Uses

func AsDString(e Expr) (DString, bool)

AsDString attempts to retrieve a DString from an Expr, returning a DString and a flag signifying whether the assertion was successful. The function should be used instead of direct type assertions wherever a *DString wrapped by a *DOidWrapper is possible.

func MustBeDString Uses

func MustBeDString(e Expr) DString

MustBeDString attempts to retrieve a DString from an Expr, panicking if the assertion fails.

func NewDString Uses

func NewDString(d string) *DString

NewDString is a helper routine to create a *DString initialized from its argument.

func (*DString) AmbiguousFormat Uses

func (*DString) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DString) Compare Uses

func (d *DString) Compare(ctx *EvalContext, other Datum) int

Compare implements the Datum interface.

func (*DString) Eval Uses

func (t *DString) Eval(_ *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*DString) Format Uses

func (d *DString) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*DString) IsMax Uses

func (*DString) IsMax() bool

IsMax implements the Datum interface.

func (*DString) IsMin Uses

func (d *DString) IsMin() bool

IsMin implements the Datum interface.

func (*DString) Next Uses

func (d *DString) Next() (Datum, bool)

Next implements the Datum interface.

func (*DString) Prev Uses

func (d *DString) Prev() (Datum, bool)

Prev implements the Datum interface.

func (*DString) ResolvedType Uses

func (*DString) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DString) Size Uses

func (d *DString) Size() uintptr

Size implements the Datum interface.

func (*DString) String Uses

func (node *DString) String() string

func (*DString) TypeCheck Uses

func (d *DString) TypeCheck(_ *SemaContext, _ Type) (TypedExpr, error)

TypeCheck implements the Expr interface. It is implemented as an idempotent identity function for Datum.

func (*DString) Walk Uses

func (expr *DString) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type DTable Uses

type DTable struct {
    ValueGenerator
}

DTable is the table Datum. It is used for datums that hold an entire table generator. See the comments in generator_builtins.go for details.

func EmptyDTable Uses

func EmptyDTable() *DTable

EmptyDTable returns a new, empty DTable.

func (*DTable) AmbiguousFormat Uses

func (*DTable) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DTable) Compare Uses

func (t *DTable) Compare(ctx *EvalContext, other Datum) int

Compare implements the Datum interface.

func (*DTable) Eval Uses

func (t *DTable) Eval(_ *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*DTable) Format Uses

func (t *DTable) Format(buf *bytes.Buffer, _ FmtFlags)

Format implements the NodeFormatter interface.

func (*DTable) IsMax Uses

func (*DTable) IsMax() bool

IsMax implements the Datum interface.

func (*DTable) IsMin Uses

func (*DTable) IsMin() bool

IsMin implements the Datum interface.

func (*DTable) Next Uses

func (*DTable) Next() (Datum, bool)

Next implements the Datum interface.

func (*DTable) Prev Uses

func (*DTable) Prev() (Datum, bool)

Prev implements the Datum interface.

func (*DTable) ResolvedType Uses

func (t *DTable) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DTable) Size Uses

func (*DTable) Size() uintptr

Size implements the Datum interface.

func (*DTable) String Uses

func (node *DTable) String() string

func (*DTable) TypeCheck Uses

func (d *DTable) TypeCheck(_ *SemaContext, _ Type) (TypedExpr, error)

TypeCheck implements the Expr interface. It is implemented as an idempotent identity function for Datum.

func (*DTable) Walk Uses

func (expr *DTable) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type DTimestamp Uses

type DTimestamp struct {
    time.Time
}

DTimestamp is the timestamp Datum.

func MakeDTimestamp Uses

func MakeDTimestamp(t time.Time, precision time.Duration) *DTimestamp

MakeDTimestamp creates a DTimestamp with specified precision.

func ParseDTimestamp Uses

func ParseDTimestamp(s string, precision time.Duration) (*DTimestamp, error)

ParseDTimestamp parses and returns the *DTimestamp Datum value represented by the provided string in UTC, or an error if parsing is unsuccessful.

func (*DTimestamp) AmbiguousFormat Uses

func (*DTimestamp) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DTimestamp) Compare Uses

func (d *DTimestamp) Compare(ctx *EvalContext, other Datum) int

Compare implements the Datum interface.

func (*DTimestamp) Eval Uses

func (t *DTimestamp) Eval(_ *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*DTimestamp) Format Uses

func (d *DTimestamp) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*DTimestamp) IsMax Uses

func (d *DTimestamp) IsMax() bool

IsMax implements the Datum interface.

func (*DTimestamp) IsMin Uses

func (d *DTimestamp) IsMin() bool

IsMin implements the Datum interface.

func (*DTimestamp) Next Uses

func (d *DTimestamp) Next() (Datum, bool)

Next implements the Datum interface.

func (*DTimestamp) Prev Uses

func (d *DTimestamp) Prev() (Datum, bool)

Prev implements the Datum interface.

func (*DTimestamp) ResolvedType Uses

func (*DTimestamp) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DTimestamp) Size Uses

func (d *DTimestamp) Size() uintptr

Size implements the Datum interface.

func (*DTimestamp) String Uses

func (node *DTimestamp) String() string

func (*DTimestamp) TypeCheck Uses

func (d *DTimestamp) TypeCheck(_ *SemaContext, _ Type) (TypedExpr, error)

TypeCheck implements the Expr interface. It is implemented as an idempotent identity function for Datum.

func (*DTimestamp) Walk Uses

func (expr *DTimestamp) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type DTimestampTZ Uses

type DTimestampTZ struct {
    time.Time
}

DTimestampTZ is the timestamp Datum that is rendered with session offset.

func MakeDTimestampTZ Uses

func MakeDTimestampTZ(t time.Time, precision time.Duration) *DTimestampTZ

MakeDTimestampTZ creates a DTimestampTZ with specified precision.

func MakeDTimestampTZFromDate Uses

func MakeDTimestampTZFromDate(loc *time.Location, d *DDate) *DTimestampTZ

MakeDTimestampTZFromDate creates a DTimestampTZ from a DDate.

func ParseDTimestampTZ Uses

func ParseDTimestampTZ(
    s string, loc *time.Location, precision time.Duration,
) (*DTimestampTZ, error)

ParseDTimestampTZ parses and returns the *DTimestampTZ Datum value represented by the provided string in the provided location, or an error if parsing is unsuccessful.

func (*DTimestampTZ) AmbiguousFormat Uses

func (*DTimestampTZ) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DTimestampTZ) Compare Uses

func (d *DTimestampTZ) Compare(ctx *EvalContext, other Datum) int

Compare implements the Datum interface.

func (*DTimestampTZ) Eval Uses

func (t *DTimestampTZ) Eval(_ *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*DTimestampTZ) Format Uses

func (d *DTimestampTZ) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*DTimestampTZ) IsMax Uses

func (d *DTimestampTZ) IsMax() bool

IsMax implements the Datum interface.

func (*DTimestampTZ) IsMin Uses

func (d *DTimestampTZ) IsMin() bool

IsMin implements the Datum interface.

func (*DTimestampTZ) Next Uses

func (d *DTimestampTZ) Next() (Datum, bool)

Next implements the Datum interface.

func (*DTimestampTZ) Prev Uses

func (d *DTimestampTZ) Prev() (Datum, bool)

Prev implements the Datum interface.

func (*DTimestampTZ) ResolvedType Uses

func (*DTimestampTZ) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DTimestampTZ) Size Uses

func (d *DTimestampTZ) Size() uintptr

Size implements the Datum interface.

func (*DTimestampTZ) String Uses

func (node *DTimestampTZ) String() string

func (*DTimestampTZ) TypeCheck Uses

func (d *DTimestampTZ) TypeCheck(_ *SemaContext, _ Type) (TypedExpr, error)

TypeCheck implements the Expr interface. It is implemented as an idempotent identity function for Datum.

func (*DTimestampTZ) Walk Uses

func (expr *DTimestampTZ) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type DTuple Uses

type DTuple struct {
    D   Datums

    Sorted bool
}

DTuple is the tuple Datum.

func NewDTuple Uses

func NewDTuple(d ...Datum) *DTuple

NewDTuple creates a *DTuple with the provided datums. When creating a new DTuple with Datums that are known to be sorted in ascending order, chain this call with DTuple.SetSorted.

func NewDTupleWithCap Uses

func NewDTupleWithCap(c int) *DTuple

NewDTupleWithCap creates a *DTuple with the provided capacity.

func NewDTupleWithLen Uses

func NewDTupleWithLen(l int) *DTuple

NewDTupleWithLen creates a *DTuple with the provided length.

func (*DTuple) AmbiguousFormat Uses

func (*DTuple) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DTuple) AssertSorted Uses

func (d *DTuple) AssertSorted()

AssertSorted asserts that the DTuple is sorted.

func (*DTuple) Compare Uses

func (d *DTuple) Compare(ctx *EvalContext, other Datum) int

Compare implements the Datum interface.

func (*DTuple) Eval Uses

func (t *DTuple) Eval(_ *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*DTuple) Format Uses

func (d *DTuple) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*DTuple) IsMax Uses

func (d *DTuple) IsMax() bool

IsMax implements the Datum interface.

func (*DTuple) IsMin Uses

func (d *DTuple) IsMin() bool

IsMin implements the Datum interface.

func (*DTuple) Next Uses

func (d *DTuple) Next() (Datum, bool)

Next implements the Datum interface.

func (*DTuple) Normalize Uses

func (d *DTuple) Normalize(ctx *EvalContext)

Normalize sorts and uniques the datum tuple.

func (*DTuple) Prev Uses

func (d *DTuple) Prev() (Datum, bool)

Prev implements the Datum interface.

func (*DTuple) ResolvedType Uses

func (d *DTuple) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DTuple) SearchSorted Uses

func (d *DTuple) SearchSorted(ctx *EvalContext, target Datum) (int, bool)

SearchSorted searches the tuple for the target Datum, returning an int with the same contract as sort.Search and a boolean flag signifying whether the datum was found. It assumes that the DTuple is sorted and panics if it is not.

func (*DTuple) SetSorted Uses

func (d *DTuple) SetSorted() *DTuple

SetSorted sets the sorted flag on the DTuple. This should be used when a DTuple is known to be sorted based on the datums added to it.

func (*DTuple) Size Uses

func (d *DTuple) Size() uintptr

Size implements the Datum interface.

func (*DTuple) SortedDifference Uses

func (d *DTuple) SortedDifference(ctx *EvalContext, other *DTuple) *DTuple

SortedDifference finds the elements of d which are not in other, assuming that d and other are already sorted.

func (*DTuple) String Uses

func (node *DTuple) String() string

func (*DTuple) TypeCheck Uses

func (d *DTuple) TypeCheck(_ *SemaContext, _ Type) (TypedExpr, error)

TypeCheck implements the Expr interface. It is implemented as an idempotent identity function for Datum.

func (*DTuple) Walk Uses

func (expr *DTuple) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type DUuid Uses

type DUuid struct {
    uuid.UUID
}

DUuid is the UUID Datum.

func NewDUuid Uses

func NewDUuid(d DUuid) *DUuid

NewDUuid is a helper routine to create a *DUuid initialized from its argument.

func ParseDUuidFromBytes Uses

func ParseDUuidFromBytes(b []byte) (*DUuid, error)

ParseDUuidFromBytes parses and returns the *DUuid Datum value represented by the provided input bytes, or an error.

func ParseDUuidFromString Uses

func ParseDUuidFromString(s string) (*DUuid, error)

ParseDUuidFromString parses and returns the *DUuid Datum value represented by the provided input string, or an error.

func (*DUuid) AmbiguousFormat Uses

func (*DUuid) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DUuid) Compare Uses

func (d *DUuid) Compare(ctx *EvalContext, other Datum) int

Compare implements the Datum interface.

func (*DUuid) Eval Uses

func (t *DUuid) Eval(_ *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*DUuid) Format Uses

func (d *DUuid) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*DUuid) IsMax Uses

func (d *DUuid) IsMax() bool

IsMax implements the Datum interface.

func (*DUuid) IsMin Uses

func (d *DUuid) IsMin() bool

IsMin implements the Datum interface.

func (*DUuid) Next Uses

func (d *DUuid) Next() (Datum, bool)

Next implements the Datum interface.

func (*DUuid) Prev Uses

func (d *DUuid) Prev() (Datum, bool)

Prev implements the Datum interface.

func (*DUuid) ResolvedType Uses

func (*DUuid) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DUuid) Size Uses

func (d *DUuid) Size() uintptr

Size implements the Datum interface.

func (*DUuid) String Uses

func (node *DUuid) String() string

func (*DUuid) TypeCheck Uses

func (d *DUuid) TypeCheck(_ *SemaContext, _ Type) (TypedExpr, error)

TypeCheck implements the Expr interface. It is implemented as an idempotent identity function for Datum.

func (*DUuid) Walk Uses

func (expr *DUuid) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type DateColType Uses

type DateColType struct {
}

DateColType represents a DATE type.

func (*DateColType) Format Uses

func (node *DateColType) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*DateColType) String Uses

func (node *DateColType) String() string

type Datum Uses

type Datum interface {
    TypedExpr

    // AmbiguousFormat indicates whether the result of formatting this Datum can
    // be interpreted into more than one type. Used with
    // fmtFlags.disambiguateDatumTypes.
    AmbiguousFormat() bool

    // Compare returns -1 if the receiver is less than other, 0 if receiver is
    // equal to other and +1 if receiver is greater than other.
    Compare(ctx *EvalContext, other Datum) int

    // Prev returns the previous datum and true, if one exists, or nil and false.
    // The previous datum satisfies the following definition: if the receiver is
    // "b" and the returned datum is "a", then for every compatible datum "x", it
    // holds that "x < b" is true if and only if "x <= a" is true.
    //
    // The return value is undefined if IsMin() returns true.
    //
    // TODO(#12022): for DTuple, the contract is actually that "x < b" (SQL order,
    // where NULL < x is unknown for all x) is true only if "x <= a"
    // (.Compare/encoding order, where NULL <= x is true for all x) is true. This
    // is okay for now: the returned datum is used only to construct a span, which
    // uses .Compare/encoding order and is guaranteed to be large enough by this
    // weaker contract. The original filter expression is left in place to catch
    // false positives.
    Prev() (Datum, bool)

    // IsMin returns true if the datum is equal to the minimum value the datum
    // type can hold.
    IsMin() bool

    // Next returns the next datum and true, if one exists, or nil and false
    // otherwise. The next datum satisfies the following definition: if the
    // receiver is "a" and the returned datum is "b", then for every compatible
    // datum "x", it holds that "x > a" is true if and only if "x >= b" is true.
    //
    // The return value is undefined if IsMax() returns true.
    //
    // TODO(#12022): for DTuple, the contract is actually that "x > a" (SQL order,
    // where x > NULL is unknown for all x) is true only if "x >= b"
    // (.Compare/encoding order, where x >= NULL is true for all x) is true. This
    // is okay for now: the returned datum is used only to construct a span, which
    // uses .Compare/encoding order and is guaranteed to be large enough by this
    // weaker contract. The original filter expression is left in place to catch
    // false positives.
    Next() (Datum, bool)

    // IsMax returns true if the datum is equal to the maximum value the datum
    // type can hold.
    IsMax() bool

    // Size returns a lower bound on the total size of the receiver in bytes,
    // including memory that is pointed at (even if shared between Datum
    // instances) but excluding allocation overhead.
    //
    // It holds for every Datum d that d.Size() >= d.ResolvedType().Size().
    Size() uintptr
    // contains filtered or unexported methods
}

Datum represents a SQL value.

func NewDIntVectorFromDArray Uses

func NewDIntVectorFromDArray(d *DArray) Datum

NewDIntVectorFromDArray is a helper routine to create a *DIntVector (implemented as a *DOidWrapper) initialized from an existing *DArray.

func NewDName Uses

func NewDName(d string) Datum

NewDName is a helper routine to create a *DName (implemented as a *DOidWrapper) initialized from a string.

func NewDNameFromDString Uses

func NewDNameFromDString(d *DString) Datum

NewDNameFromDString is a helper routine to create a *DName (implemented as a *DOidWrapper) initialized from an existing *DString.

func UnwrapDatum Uses

func UnwrapDatum(d Datum) Datum

UnwrapDatum returns the base Datum type for a provided datum, stripping an *DOidWrapper if present. This is useful for cases like type switches, where type aliases should be ignored.

type Datums Uses

type Datums []Datum

Datums is a slice of Datum values.

func (Datums) Format Uses

func (d Datums) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (Datums) Len Uses

func (d Datums) Len() int

Len returns the number of Datum values.

func (Datums) Reverse Uses

func (d Datums) Reverse()

Reverse reverses the order of the Datum values.

func (*Datums) String Uses

func (node *Datums) String() string

type Deallocate Uses

type Deallocate struct {
    Name Name // empty for ALL
}

Deallocate represents a DEALLOCATE statement.

func (*Deallocate) Format Uses

func (node *Deallocate) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*Deallocate) StatementTag Uses

func (n *Deallocate) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Deallocate) StatementType Uses

func (*Deallocate) StatementType() StatementType

StatementType implements the Statement interface.

func (*Deallocate) String Uses

func (n *Deallocate) String() string

type DecimalColType Uses

type DecimalColType struct {
    Name  string
    Prec  int
    Scale int
}

DecimalColType represents a DECIMAL or NUMERIC type.

func (*DecimalColType) Format Uses

func (node *DecimalColType) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*DecimalColType) String Uses

func (node *DecimalColType) String() string

type DefaultVal Uses

type DefaultVal struct{}

DefaultVal represents the DEFAULT expression.

func (DefaultVal) Eval Uses

func (expr DefaultVal) Eval(ctx *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (DefaultVal) Format Uses

func (node DefaultVal) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (DefaultVal) ResolvedType Uses

func (DefaultVal) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (DefaultVal) String Uses

func (node DefaultVal) String() string

func (DefaultVal) TypeCheck Uses

func (expr DefaultVal) TypeCheck(_ *SemaContext, desired Type) (TypedExpr, error)

TypeCheck implements the Expr interface.

func (DefaultVal) Walk Uses

func (expr DefaultVal) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type Delete Uses

type Delete struct {
    Table     TableExpr
    Where     *Where
    Returning ReturningClause
}

Delete represents a DELETE statement.

func (*Delete) CopyNode Uses

func (stmt *Delete) CopyNode() *Delete

CopyNode makes a copy of this Statement without recursing in any child Statements.

func (*Delete) Format Uses

func (node *Delete) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*Delete) StatementTag Uses

func (*Delete) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Delete) StatementType Uses

func (n *Delete) StatementType() StatementType

StatementType implements the Statement interface.

func (*Delete) String Uses

func (n *Delete) String() string

func (*Delete) WalkStmt Uses

func (stmt *Delete) WalkStmt(v Visitor) Statement

WalkStmt is part of the WalkableStmt interface.

type Direction Uses

type Direction int

Direction for ordering results.

const (
    DefaultDirection Direction = iota
    Ascending
    Descending
)

Direction values.

func (Direction) String Uses

func (d Direction) String() string

type DropBehavior Uses

type DropBehavior int

DropBehavior represents options for dropping schema elements.

const (
    DropDefault DropBehavior = iota
    DropRestrict
    DropCascade
)

DropBehavior values.

func (DropBehavior) String Uses

func (d DropBehavior) String() string

type DropDatabase Uses

type DropDatabase struct {
    Name     Name
    IfExists bool
}

DropDatabase represents a DROP DATABASE statement.

func (*DropDatabase) Format Uses

func (node *DropDatabase) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*DropDatabase) StatementTag Uses

func (*DropDatabase) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*DropDatabase) StatementType Uses

func (*DropDatabase) StatementType() StatementType

StatementType implements the Statement interface.

func (*DropDatabase) String Uses

func (n *DropDatabase) String() string

type DropIndex Uses

type DropIndex struct {
    IndexList    TableNameWithIndexList
    IfExists     bool
    DropBehavior DropBehavior
}

DropIndex represents a DROP INDEX statement.

func (*DropIndex) Format Uses

func (node *DropIndex) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*DropIndex) StatementTag Uses

func (*DropIndex) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*DropIndex) StatementType Uses

func (*DropIndex) StatementType() StatementType

StatementType implements the Statement interface.

func (*DropIndex) String Uses

func (n *DropIndex) String() string

type DropTable Uses

type DropTable struct {
    Names        TableNameReferences
    IfExists     bool
    DropBehavior DropBehavior
}

DropTable represents a DROP TABLE statement.

func (*DropTable) Format Uses

func (node *DropTable) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*DropTable) StatementTag Uses

func (*DropTable) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*DropTable) StatementType Uses

func (*DropTable) StatementType() StatementType

StatementType implements the Statement interface.

func (*DropTable) String Uses

func (n *DropTable) String() string

type DropUser Uses

type DropUser struct {
    Names    NameList
    IfExists bool
}

DropUser represents a DROP USER statement

func (*DropUser) Format Uses

func (node *DropUser) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*DropUser) StatementTag Uses

func (*DropUser) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*DropUser) StatementType Uses

func (*DropUser) StatementType() StatementType

StatementType implements the Statement interface.

func (*DropUser) String Uses

func (n *DropUser) String() string

type DropView Uses

type DropView struct {
    Names        TableNameReferences
    IfExists     bool
    DropBehavior DropBehavior
}

DropView represents a DROP VIEW statement.

func (*DropView) Format Uses

func (node *DropView) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*DropView) StatementTag Uses

func (*DropView) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*DropView) StatementType Uses

func (*DropView) StatementType() StatementType

StatementType implements the Statement interface.

func (*DropView) String Uses

func (n *DropView) String() string

type EvalContext Uses

type EvalContext struct {
    ClusterID uuid.UUID
    NodeID    roachpb.NodeID

    // Location references the *Location on the current Session.
    Location **time.Location
    // Database is the database in the current Session.
    Database string
    // SearchPath is the search path for databases used when encountering an
    // unqualified table name. Names in the search path are normalized already.
    // This must not be modified (this is shared from the session).
    SearchPath SearchPath
    // Ctx represents the context in which the expression is evaluated. This will
    // point to the Session's context container.
    // NOTE: seems a bit lazy to hold a pointer to the session's context here,
    // instead of making sure the right context is explicitly set before the
    // EvalContext is used. But there's already precedent with the Location field,
    // and also at the time of writing, EvalContexts are initialized with the
    // planner and not mutated.
    Ctx contextHolder

    Planner EvalPlanner

    ReCache *RegexpCache

    // TODO(mjibson): remove prepareOnly in favor of a 2-step prepare-exec solution
    // that is also able to save the plan to skip work during the exec step.
    PrepareOnly bool

    // SkipNormalize indicates whether expressions should be normalized
    // (false) or not (true).  It is set to true conditionally by
    // EXPLAIN(TYPES[, NORMALIZE]).
    SkipNormalize bool

    Mon *mon.MemoryMonitor

    // ActiveMemAcc is the account to which values are allocated during
    // evaluation. It can change over the course of evaluation, such as on a
    // per-row basis.
    ActiveMemAcc *mon.BoundAccount
    // contains filtered or unexported fields
}

EvalContext defines the context in which to evaluate an expression, allowing the retrieval of state such as the node ID or statement start time.

ATTENTION: Fields from this struct are also represented in distsqlrun.EvalContext. Make sure to keep the two in sync. TODO(andrei): remove or limit the duplication.

func MakeTestingEvalContext Uses

func MakeTestingEvalContext() EvalContext

MakeTestingEvalContext returns an EvalContext that includes a MemoryMonitor.

func NewTestingEvalContext Uses

func NewTestingEvalContext() *EvalContext

NewTestingEvalContext is a convenience version of MakeTestingEvalContext that returns a pointer.

func (*EvalContext) GetClusterTimestamp Uses

func (ctx *EvalContext) GetClusterTimestamp() *DDecimal

GetClusterTimestamp retrieves the current cluster timestamp as per the evaluation context. The timestamp is guaranteed to be nonzero.

func (*EvalContext) GetClusterTimestampRaw Uses

func (ctx *EvalContext) GetClusterTimestampRaw() hlc.Timestamp

GetClusterTimestampRaw exposes the clusterTimestamp field. Also see GetClusterTimestamp().

func (*EvalContext) GetLocation Uses

func (ctx *EvalContext) GetLocation() *time.Location

GetLocation returns the session timezone.

func (*EvalContext) GetStmtTimestamp Uses

func (ctx *EvalContext) GetStmtTimestamp() time.Time

GetStmtTimestamp retrieves the current statement timestamp as per the evaluation context. The timestamp is guaranteed to be nonzero.

func (*EvalContext) GetTxnTimestamp Uses

func (ctx *EvalContext) GetTxnTimestamp(precision time.Duration) *DTimestampTZ

GetTxnTimestamp retrieves the current transaction timestamp as per the evaluation context. The timestamp is guaranteed to be nonzero.

func (*EvalContext) GetTxnTimestampNoZone Uses

func (ctx *EvalContext) GetTxnTimestampNoZone(precision time.Duration) *DTimestamp

GetTxnTimestampNoZone retrieves the current transaction timestamp as per the evaluation context. The timestamp is guaranteed to be nonzero.

func (*EvalContext) GetTxnTimestampRaw Uses

func (ctx *EvalContext) GetTxnTimestampRaw() time.Time

GetTxnTimestampRaw exposes the txnTimestamp field. Also see GetTxnTimestamp() and GetTxnTimestampNoZone().

func (*EvalContext) NormalizeExpr Uses

func (ctx *EvalContext) NormalizeExpr(typedExpr TypedExpr) (TypedExpr, error)

NormalizeExpr normalizes a typed expression, simplifying where possible, but guaranteeing that the result of evaluating the expression is unchanged and that resulting expression tree is still well-typed. Example normalizations:

(a)                   -> a
a = 1 + 1             -> a = 2
a + 1 = 2             -> a = 1
a BETWEEN b AND c     -> (a >= b) AND (a <= c)
a NOT BETWEEN b AND c -> (a < b) OR (a > c)

func (*EvalContext) SetClusterTimestamp Uses

func (ctx *EvalContext) SetClusterTimestamp(ts hlc.Timestamp)

SetClusterTimestamp sets the corresponding timestamp in the EvalContext.

func (*EvalContext) SetStmtTimestamp Uses

func (ctx *EvalContext) SetStmtTimestamp(ts time.Time)

SetStmtTimestamp sets the corresponding timestamp in the EvalContext.

func (*EvalContext) SetTxnTimestamp Uses

func (ctx *EvalContext) SetTxnTimestamp(ts time.Time)

SetTxnTimestamp sets the corresponding timestamp in the EvalContext.

func (*EvalContext) Stop Uses

func (ctx *EvalContext) Stop(c context.Context)

Stop closes out the EvalContext and must be called once it is no longer in use.

type EvalPlanner Uses

type EvalPlanner interface {
    // QueryRow executes a SQL query string where exactly 1 result row is
    // expected and returns that row.
    QueryRow(ctx context.Context, sql string, args ...interface{}) (Datums, error)

    // QualifyWithDatabase resolves a possibly unqualified table name into a
    // table name that is qualified by database.
    QualifyWithDatabase(ctx context.Context, t *NormalizableTableName) (*TableName, error)
}

EvalPlanner is a limited planner that can be used from EvalContext.

type Execute Uses

type Execute struct {
    Name   Name
    Params Exprs
}

Execute represents an EXECUTE statement.

func (*Execute) Format Uses

func (node *Execute) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*Execute) StatementTag Uses

func (*Execute) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Execute) StatementType Uses

func (*Execute) StatementType() StatementType

StatementType implements the Statement interface.

func (*Execute) String Uses

func (n *Execute) String() string

type ExistsExpr Uses

type ExistsExpr struct {
    Subquery Expr
    // contains filtered or unexported fields
}

ExistsExpr represents an EXISTS expression.

func (*ExistsExpr) Eval Uses

func (t *ExistsExpr) Eval(ctx *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*ExistsExpr) Format Uses

func (node *ExistsExpr) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (ExistsExpr) ResolvedType Uses

func (ta ExistsExpr) ResolvedType() Type

func (*ExistsExpr) String Uses

func (node *ExistsExpr) String() string

func (*ExistsExpr) TypeCheck Uses

func (expr *ExistsExpr) TypeCheck(ctx *SemaContext, desired Type) (TypedExpr, error)

TypeCheck implements the Expr interface.

func (*ExistsExpr) Walk Uses

func (expr *ExistsExpr) Walk(v Visitor) Expr

Walk implements the Expr interface.

type Explain Uses

type Explain struct {
    // Options defines how EXPLAIN should operate (VERBOSE, METADATA,
    // etc.) Which options are valid depends on the explain mode. See
    // sql/explain.go for details.
    Options []string

    // Statement is the statement being EXPLAINed.
    Statement Statement
}

Explain represents an EXPLAIN statement.

func (*Explain) CopyNode Uses

func (stmt *Explain) CopyNode() *Explain

CopyNode makes a copy of this Statement without recursing in any child Statements.

func