parser

package
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2017 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DistinctFuncType funcType
	AllFuncType
)

FuncExpr.Type

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

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

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

MaxInt is the maximum value of an int.

View Source
const MaxUint = ^uint(0)

MaxUint is the maximum value of an uint.

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

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

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

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

time.Time formats.

View Source
const UMINUS = 57654
View Source
const UNBOUNDED = 57623
View Source
const UNCOMMITTED = 57624
View Source
const UNION = 57625
View Source
const UNIQUE = 57626
View Source
const UNKNOWN = 57627
View Source
const UPDATE = 57628
View Source
const UPSERT = 57629
View Source
const USER = 57630
View Source
const USERS = 57631
View Source
const USING = 57632
View Source
const VALID = 57633
View Source
const VALIDATE = 57634
View Source
const VALUE = 57635
View Source
const VALUES = 57636
View Source
const VARCHAR = 57637
View Source
const VARIADIC = 57638
View Source
const VARYING = 57640
View Source
const VIEW = 57639
View Source
const WHEN = 57641
View Source
const WHERE = 57642
View Source
const WINDOW = 57643
View Source
const WITH = 57644
View Source
const WITHIN = 57645
View Source
const WITHOUT = 57646
View Source
const WITH_LA = 57651
View Source
const WRITE = 57647
View Source
const YEAR = 57648
View Source
const ZONE = 57649

Variables

View Source
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)
)
View Source
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
	}()
)
View Source
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{}
	// 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,
		TypeOid,
	}
)
View Source
var AbsentReturningClause = &NoReturningClause{}

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

View Source
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."),
	},

	"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."),
	},
}

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.

View Source
var BinOps = map[BinaryOperator]binOpOverload{
	Bitand: {
		BinOp{
			LeftType:   TypeInt,
			RightType:  TypeInt,
			ReturnType: TypeInt,
			// contains filtered or unexported fields
		},
	},

	Bitor: {
		BinOp{
			LeftType:   TypeInt,
			RightType:  TypeInt,
			ReturnType: TypeInt,
			// contains filtered or unexported fields
		},
	},

	Bitxor: {
		BinOp{
			LeftType:   TypeInt,
			RightType:  TypeInt,
			ReturnType: TypeInt,
			// contains filtered or unexported fields
		},
	},

	Plus: {
		BinOp{
			LeftType:   TypeInt,
			RightType:  TypeInt,
			ReturnType: TypeInt,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeFloat,
			RightType:  TypeFloat,
			ReturnType: TypeFloat,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeDecimal,
			RightType:  TypeDecimal,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeDecimal,
			RightType:  TypeInt,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeInt,
			RightType:  TypeDecimal,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeDate,
			RightType:  TypeInt,
			ReturnType: TypeDate,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeInt,
			RightType:  TypeDate,
			ReturnType: TypeDate,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeTimestamp,
			RightType:  TypeInterval,
			ReturnType: TypeTimestamp,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeInterval,
			RightType:  TypeTimestamp,
			ReturnType: TypeTimestamp,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeTimestampTZ,
			RightType:  TypeInterval,
			ReturnType: TypeTimestampTZ,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeInterval,
			RightType:  TypeTimestampTZ,
			ReturnType: TypeTimestampTZ,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeInterval,
			RightType:  TypeInterval,
			ReturnType: TypeInterval,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeDate,
			RightType:  TypeInterval,
			ReturnType: TypeTimestampTZ,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeInterval,
			RightType:  TypeDate,
			ReturnType: TypeTimestampTZ,
			// contains filtered or unexported fields
		},
	},

	Minus: {
		BinOp{
			LeftType:   TypeInt,
			RightType:  TypeInt,
			ReturnType: TypeInt,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeFloat,
			RightType:  TypeFloat,
			ReturnType: TypeFloat,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeDecimal,
			RightType:  TypeDecimal,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeDecimal,
			RightType:  TypeInt,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeInt,
			RightType:  TypeDecimal,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeDate,
			RightType:  TypeInt,
			ReturnType: TypeDate,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeDate,
			RightType:  TypeDate,
			ReturnType: TypeInt,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeTimestamp,
			RightType:  TypeTimestamp,
			ReturnType: TypeInterval,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeTimestampTZ,
			RightType:  TypeTimestampTZ,
			ReturnType: TypeInterval,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeTimestamp,
			RightType:  TypeTimestampTZ,
			ReturnType: TypeInterval,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeTimestampTZ,
			RightType:  TypeTimestamp,
			ReturnType: TypeInterval,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeTimestamp,
			RightType:  TypeInterval,
			ReturnType: TypeTimestamp,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeTimestampTZ,
			RightType:  TypeInterval,
			ReturnType: TypeTimestampTZ,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeDate,
			RightType:  TypeInterval,
			ReturnType: TypeTimestampTZ,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeInterval,
			RightType:  TypeInterval,
			ReturnType: TypeInterval,
			// contains filtered or unexported fields
		},
	},

	Mult: {
		BinOp{
			LeftType:   TypeInt,
			RightType:  TypeInt,
			ReturnType: TypeInt,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeFloat,
			RightType:  TypeFloat,
			ReturnType: TypeFloat,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeDecimal,
			RightType:  TypeDecimal,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},

		BinOp{
			LeftType:   TypeDecimal,
			RightType:  TypeInt,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeInt,
			RightType:  TypeDecimal,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeInt,
			RightType:  TypeInterval,
			ReturnType: TypeInterval,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeInterval,
			RightType:  TypeInt,
			ReturnType: TypeInterval,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeInterval,
			RightType:  TypeFloat,
			ReturnType: TypeInterval,
			// contains filtered or unexported fields
		},
	},

	Div: {
		BinOp{
			LeftType:   TypeInt,
			RightType:  TypeInt,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeFloat,
			RightType:  TypeFloat,
			ReturnType: TypeFloat,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeDecimal,
			RightType:  TypeDecimal,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeDecimal,
			RightType:  TypeInt,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeInt,
			RightType:  TypeDecimal,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeInterval,
			RightType:  TypeInt,
			ReturnType: TypeInterval,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeInterval,
			RightType:  TypeFloat,
			ReturnType: TypeInterval,
			// contains filtered or unexported fields
		},
	},

	FloorDiv: {
		BinOp{
			LeftType:   TypeInt,
			RightType:  TypeInt,
			ReturnType: TypeInt,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeFloat,
			RightType:  TypeFloat,
			ReturnType: TypeFloat,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeDecimal,
			RightType:  TypeDecimal,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeDecimal,
			RightType:  TypeInt,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeInt,
			RightType:  TypeDecimal,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
	},

	Mod: {
		BinOp{
			LeftType:   TypeInt,
			RightType:  TypeInt,
			ReturnType: TypeInt,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeFloat,
			RightType:  TypeFloat,
			ReturnType: TypeFloat,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeDecimal,
			RightType:  TypeDecimal,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeDecimal,
			RightType:  TypeInt,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeInt,
			RightType:  TypeDecimal,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
	},

	Concat: {
		BinOp{
			LeftType:   TypeString,
			RightType:  TypeString,
			ReturnType: TypeString,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeBytes,
			RightType:  TypeBytes,
			ReturnType: TypeBytes,
			// contains filtered or unexported fields
		},
	},

	LShift: {
		BinOp{
			LeftType:   TypeInt,
			RightType:  TypeInt,
			ReturnType: TypeInt,
			// contains filtered or unexported fields
		},
	},

	RShift: {
		BinOp{
			LeftType:   TypeInt,
			RightType:  TypeInt,
			ReturnType: TypeInt,
			// contains filtered or unexported fields
		},
	},

	Pow: {
		BinOp{
			LeftType:   TypeInt,
			RightType:  TypeInt,
			ReturnType: TypeInt,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeFloat,
			RightType:  TypeFloat,
			ReturnType: TypeFloat,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeDecimal,
			RightType:  TypeDecimal,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeDecimal,
			RightType:  TypeInt,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
		BinOp{
			LeftType:   TypeInt,
			RightType:  TypeDecimal,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
	},
}

BinOps contains the binary operations indexed by operation type.

View Source
var Builtins = map[string][]Builtin{

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

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

	"lower": {stringBuiltin1(func(s string) (Datum, error) {
		return NewDString(strings.ToLower(s)), nil
	}, TypeString, "Converts all characters in `val`to their lower-case equivalents.")},

	"upper": {stringBuiltin1(func(s string) (Datum, error) {
		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),

			Info: "Concatenates a comma-separated list of strings.",
			// contains filtered or unexported fields
		},
	},

	"concat_ws": {
		Builtin{
			Types:      VariadicType{TypeString},
			ReturnType: fixedReturnType(TypeString),

			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`.",
			// contains filtered or unexported fields
		},
	},

	"to_uuid": {
		Builtin{
			Types:      ArgTypes{{"val", TypeString}},
			ReturnType: fixedReturnType(TypeBytes),

			Info: "Converts the character string representation of a UUID to its byte string " +
				"representation.",
			// contains filtered or unexported fields
		},
	},

	"from_uuid": {
		Builtin{
			Types:      ArgTypes{{"val", TypeBytes}},
			ReturnType: fixedReturnType(TypeString),

			Info: "Converts the byte string representation of a UUID to its character string " +
				"representation.",
			// contains filtered or unexported fields
		},
	},

	"from_ip": {
		Builtin{
			Types:      ArgTypes{{"val", TypeBytes}},
			ReturnType: fixedReturnType(TypeString),

			Info: "Converts the byte string representation of an IP to its character string " +
				"representation.",
			// contains filtered or unexported fields
		},
	},

	"to_ip": {
		Builtin{
			Types:      ArgTypes{{"val", TypeString}},
			ReturnType: fixedReturnType(TypeBytes),

			Info: "Converts the character string representation of an IP to its byte string " +
				"representation.",
			// contains filtered or unexported fields
		},
	},

	"split_part": {
		Builtin{
			Types: ArgTypes{
				{"input", TypeString},
				{"delimiter", TypeString},
				{"return_index_pos", TypeInt},
			},
			ReturnType: fixedReturnType(TypeString),

			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`.",
			// contains filtered or unexported fields
		},
	},

	"repeat": {
		Builtin{
			Types: ArgTypes{{"input", TypeString}, {"repeat_counter", TypeInt}},

			ReturnType: fixedReturnType(TypeString),

			Info: "Concatenates `input` `repeat_counter` number of times.<br/><br/>For example, " +
				"`repeat('dog', 2)` returns `dogdog`.",
			// contains filtered or unexported fields
		},
	},

	"ascii": {stringBuiltin1(func(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": {stringBuiltin1(func(s string) (Datum, error) {
		return NewDString(fmt.Sprintf("%x", md5.Sum([]byte(s)))), nil
	}, TypeString, "Calculates the MD5 hash value of `val`.")},

	"sha1": {stringBuiltin1(func(s string) (Datum, error) {
		return NewDString(fmt.Sprintf("%x", sha1.Sum([]byte(s)))), nil
	}, TypeString, "Calculates the SHA1 hash value of `val`.")},

	"sha256": {stringBuiltin1(func(s string) (Datum, error) {
		return NewDString(fmt.Sprintf("%x", sha256.Sum256([]byte(s)))), nil
	}, TypeString, "Calculates the SHA256 hash value of `val`.")},

	"to_hex": {
		Builtin{
			Types:      ArgTypes{{"val", TypeInt}},
			ReturnType: fixedReturnType(TypeString),

			Info: "Converts `val` to its hexadecimal representation.",
			// contains filtered or unexported fields
		},
	},

	"strpos": {stringBuiltin2("input", "find", func(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),

			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`.",
			// contains filtered or unexported fields
		},
		Builtin{
			Types: ArgTypes{
				{"input", TypeString},
				{"overlay_val", TypeString},
				{"start_pos", TypeInt},
				{"end_pos", TypeInt},
			},
			ReturnType: fixedReturnType(TypeString),

			Info: "Deletes the characters in `input` between `start_pos` and `end_pos` (count " +
				"starts at 1), and then insert `overlay_val` at `start_pos`.",
			// contains filtered or unexported fields
		},
	},

	"btrim": {
		stringBuiltin2("input", "trim_chars", func(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(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(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(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(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(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(s string) (Datum, error) {
		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(input, from, to string) (Datum, error) {
			return NewDString(strings.Replace(input, from, to, -1)), nil
		},
		TypeString,
		"Replaces all occurrences of `find` with `replace` in `input`",
	)},

	"translate": {stringBuiltin3(
		"input", "find", "replace",
		func(s, from, to string) (Datum, error) {
			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),

			Info: "Returns the first match for the Regular Expression `regex` in `input`.",
			// contains filtered or unexported fields
		},
	},

	"regexp_replace": {
		Builtin{
			Types: ArgTypes{
				{"input", TypeString},
				{"regex", TypeString},
				{"replace", TypeString},
			},
			ReturnType: fixedReturnType(TypeString),

			Info: "Replaces matches for the Regular Expression `regex` in `input` with the " +
				"Regular Expression `replace`.",
			// contains filtered or unexported fields
		},
		Builtin{
			Types: ArgTypes{
				{"input", TypeString},
				{"regex", TypeString},
				{"replace", TypeString},
				{"flags", TypeString},
			},
			ReturnType: fixedReturnType(TypeString),

			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).",
			// contains filtered or unexported fields
		},
	},

	"initcap": {stringBuiltin1(func(s string) (Datum, error) {
		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),

			Info: "Returns the first `return_set` bytes from `input`.",
			// contains filtered or unexported fields
		},
		Builtin{
			Types:      ArgTypes{{"input", TypeString}, {"return_set", TypeInt}},
			ReturnType: fixedReturnType(TypeString),

			Info: "Returns the first `return_set` characters from `input`.",
			// contains filtered or unexported fields
		},
	},

	"right": {
		Builtin{
			Types:      ArgTypes{{"input", TypeBytes}, {"return_set", TypeInt}},
			ReturnType: fixedReturnType(TypeBytes),

			Info: "Returns the last `return_set` bytes from `input`.",
			// contains filtered or unexported fields
		},
		Builtin{
			Types:      ArgTypes{{"input", TypeString}, {"return_set", TypeInt}},
			ReturnType: fixedReturnType(TypeString),

			Info: "Returns the last `return_set` characters from `input`.",
			// contains filtered or unexported fields
		},
	},

	"random": {
		Builtin{
			Types:      ArgTypes{},
			ReturnType: fixedReturnType(TypeFloat),

			Info: "Returns a random float between 0 and 1.",
			// contains filtered or unexported fields
		},
	},

	"unique_rowid": {
		Builtin{
			Types:      ArgTypes{},
			ReturnType: fixedReturnType(TypeInt),

			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.",
			// contains filtered or unexported fields
		},
	},

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

	"greatest": {
		Builtin{
			Types:      HomogeneousType{},
			ReturnType: identityReturnType(0),

			Info: "Returns the element with the greatest value.",
			// contains filtered or unexported fields
		},
	},

	"least": {
		Builtin{
			Types:      HomogeneousType{},
			ReturnType: identityReturnType(0),

			Info: "Returns the element with the lowest value.",
			// contains filtered or unexported fields
		},
	},

	"experimental_strftime": {
		Builtin{
			Types:      ArgTypes{{"input", TypeTimestamp}, {"extract_format", TypeString}},
			ReturnType: fixedReturnType(TypeString),

			Info: "From `input`, extracts and formats the time as identified in `extract_format` " +
				"using standard `strftime` notation (though not all formatting is supported).",
			// contains filtered or unexported fields
		},
		Builtin{
			Types:      ArgTypes{{"input", TypeDate}, {"extract_format", TypeString}},
			ReturnType: fixedReturnType(TypeString),

			Info: "From `input`, extracts and formats the time as identified in `extract_format` " +
				"using standard `strftime` notation (though not all formatting is supported).",
			// contains filtered or unexported fields
		},
		Builtin{
			Types:      ArgTypes{{"input", TypeTimestampTZ}, {"extract_format", TypeString}},
			ReturnType: fixedReturnType(TypeString),

			Info: "From `input`, extracts and formats the time as identified in `extract_format` " +
				"using standard `strftime` notation (though not all formatting is supported).",
			// contains filtered or unexported fields
		},
	},

	"experimental_strptime": {
		Builtin{
			Types:      ArgTypes{{"input", TypeString}, {"format", TypeString}},
			ReturnType: fixedReturnType(TypeTimestampTZ),

			Info: "Returns `input` as a timestamptz using `format` (which uses standard " +
				"`strptime` formatting).",
			// contains filtered or unexported fields
		},
	},

	"age": {
		Builtin{
			Types:      ArgTypes{{"val", TypeTimestampTZ}},
			ReturnType: fixedReturnType(TypeInterval),

			Info: "Calculates the interval between `val` and the current time.",
			// contains filtered or unexported fields
		},
		Builtin{
			Types:      ArgTypes{{"begin", TypeTimestampTZ}, {"end", TypeTimestampTZ}},
			ReturnType: fixedReturnType(TypeInterval),

			Info: "Calculates the interval between `begin` and `end`.",
			// contains filtered or unexported fields
		},
	},

	"current_date": {
		Builtin{
			Types:      ArgTypes{},
			ReturnType: fixedReturnType(TypeDate),

			Info: "Returns the current date.",
			// contains filtered or unexported fields
		},
	},

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

	"statement_timestamp": {
		Builtin{
			Types:      ArgTypes{},
			ReturnType: fixedReturnType(TypeTimestampTZ),

			Info: "Returns the current statement's timestamp.",
			// contains filtered or unexported fields
		},
		Builtin{
			Types:      ArgTypes{},
			ReturnType: fixedReturnType(TypeTimestamp),

			Info: "Returns the current statement's timestamp.",
			// contains filtered or unexported fields
		},
	},

	"cluster_logical_timestamp": {
		Builtin{
			Types:      ArgTypes{},
			ReturnType: fixedReturnType(TypeDecimal),

			Info: "This function is used only by CockroachDB's developers for testing purposes.",
			// contains filtered or unexported fields
		},
	},

	"clock_timestamp": {
		Builtin{
			Types:      ArgTypes{},
			ReturnType: fixedReturnType(TypeTimestampTZ),

			Info: "Returns the current wallclock time.",
			// contains filtered or unexported fields
		},
		Builtin{
			Types:      ArgTypes{},
			ReturnType: fixedReturnType(TypeTimestamp),

			Info: "Returns the current wallclock time.",
			// contains filtered or unexported fields
		},
	},

	"extract": {
		Builtin{
			Types:      ArgTypes{{"element", TypeString}, {"input", TypeTimestamp}},
			ReturnType: fixedReturnType(TypeInt),

			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",
			// contains filtered or unexported fields
		},
		Builtin{
			Types:      ArgTypes{{"element", TypeString}, {"input", TypeDate}},
			ReturnType: fixedReturnType(TypeInt),

			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",
			// contains filtered or unexported fields
		},
	},

	"extract_duration": {
		Builtin{
			Types:      ArgTypes{{"element", TypeString}, {"input", TypeInterval}},
			ReturnType: fixedReturnType(TypeInt),

			Info: "Extracts `element` from `input`. Compatible `elements` are: <br/>&#8226; hour" +
				"<br/>&#8226; minute<br/>&#8226; second<br/>&#8226; millisecond<br/>&#8226; " +
				"microsecond",
			// contains filtered or unexported fields
		},
	},

	"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),

			Info: "Calculates the absolute value of `val`.",
			// contains filtered or unexported fields
		},
	},

	"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),

			Info: "Calculates the integer quotient of `x`/`y`.",
			// contains filtered or unexported fields
		},
	},

	"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),

			Info: "Returns true if `val` is NaN, false otherwise.",
			// contains filtered or unexported fields
		},
		Builtin{
			Types:      ArgTypes{{"val", TypeDecimal}},
			ReturnType: fixedReturnType(TypeBool),

			Info: "Returns true if `val` is NaN, false otherwise.",
			// contains filtered or unexported fields
		},
	},

	"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),

			Info: "Calculates `x`%`y`.",
			// contains filtered or unexported fields
		},
	},

	"pi": {
		Builtin{
			Types:      ArgTypes{},
			ReturnType: fixedReturnType(TypeFloat),

			Info: "Returns the value for pi (3.141592653589793).",
			// contains filtered or unexported fields
		},
	},

	"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),

			Info: "Keeps `decimal_accuracy` number of figures to the right of the zero position " +
				" in `input` using half to even (banker's) rounding.",
			// contains filtered or unexported fields
		},
		Builtin{
			Types:      ArgTypes{{"input", TypeDecimal}, {"decimal_accuracy", TypeInt}},
			ReturnType: fixedReturnType(TypeDecimal),

			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.",
			// contains filtered or unexported fields
		},
	},

	"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),

			Info: "Determines the sign of `val`: **1** for positive; **0** for 0 values; **-1** " +
				"for negative.",
			// contains filtered or unexported fields
		},
	},

	"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),

			Info: "This function enunciates the value of its argument using English cardinals.",
			// contains filtered or unexported fields
		},
	},

	"array_length": {
		Builtin{
			Types:      ArgTypes{{"input", TypeAnyArray}, {"array_dimension", TypeInt}},
			ReturnType: fixedReturnType(TypeInt),

			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**.",
			// contains filtered or unexported fields
		},
	},

	"array_lower": {
		Builtin{
			Types:      ArgTypes{{"input", TypeAnyArray}, {"array_dimension", TypeInt}},
			ReturnType: fixedReturnType(TypeInt),

			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**.",
			// contains filtered or unexported fields
		},
	},

	"array_upper": {
		Builtin{
			Types:      ArgTypes{{"input", TypeAnyArray}, {"array_dimension", TypeInt}},
			ReturnType: fixedReturnType(TypeInt),

			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**.",
			// contains filtered or unexported fields
		},
	},

	"version": {
		Builtin{
			Types:      ArgTypes{},
			ReturnType: fixedReturnType(TypeString),

			Info: "Returns the node's version of CockroachDB.",
			// contains filtered or unexported fields
		},
	},

	"current_database": {
		Builtin{
			Types:      ArgTypes{},
			ReturnType: fixedReturnType(TypeString),

			Info: "Returns the current database.",
			// contains filtered or unexported fields
		},
	},

	"current_schema": {
		Builtin{
			Types:      ArgTypes{},
			ReturnType: fixedReturnType(TypeString),

			Info: "Returns the current schema. This function is provided for " +
				"compatibility with PostgreSQL. For a new CockroachDB application, " +
				"consider using current_database() instead.",
			// contains filtered or unexported fields
		},
	},

	"current_schemas": {
		Builtin{
			Types:      ArgTypes{{"include_pg_catalog", TypeBool}},
			ReturnType: fixedReturnType(TypeStringArray),

			Info: "Returns the current search path for unqualified names.",
			// contains filtered or unexported fields
		},
	},

	"crdb_internal.force_internal_error": {
		Builtin{
			Types:      ArgTypes{{"msg", TypeString}},
			ReturnType: fixedReturnType(TypeInt),

			Info: "This function is used only by CockroachDB's developers for testing purposes.",
			// contains filtered or unexported fields
		},
	},

	"crdb_internal.force_panic": {
		Builtin{
			Types:      ArgTypes{{"msg", TypeString}},
			ReturnType: fixedReturnType(TypeInt),

			Info: "This function is used only by CockroachDB's developers for testing purposes.",
			// contains filtered or unexported fields
		},
	},

	"crdb_internal.force_log_fatal": {
		Builtin{
			Types:      ArgTypes{{"msg", TypeString}},
			ReturnType: fixedReturnType(TypeInt),

			Info: "This function is used only by CockroachDB's developers for testing purposes.",
			// contains filtered or unexported fields
		},
	},

	"crdb_internal.force_retry": {
		Builtin{
			Types:      ArgTypes{{"val", TypeInterval}},
			ReturnType: fixedReturnType(TypeInt),

			Info: "This function is used only by CockroachDB's developers for testing purposes.",
			// contains filtered or unexported fields
		},
		Builtin{
			Types: ArgTypes{
				{"val", TypeInterval},
				{"txnID", TypeString}},
			ReturnType: fixedReturnType(TypeInt),

			Info: "This function is used only by CockroachDB's developers for testing purposes.",
			// contains filtered or unexported fields
		},
	},
}

Builtins contains the built-in functions indexed by name.

View Source
var CmpOps = map[ComparisonOperator]cmpOpOverload{
	EQ: {
		CmpOp{
			LeftType:  TypeString,
			RightType: TypeString,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeCollatedString,
			RightType: TypeCollatedString,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeBytes,
			RightType: TypeBytes,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeBool,
			RightType: TypeBool,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeInt,
			RightType: TypeInt,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeFloat,
			RightType: TypeFloat,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDecimal,
			RightType: TypeDecimal,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeFloat,
			RightType: TypeInt,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeInt,
			RightType: TypeFloat,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDecimal,
			RightType: TypeInt,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeInt,
			RightType: TypeDecimal,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDecimal,
			RightType: TypeFloat,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeFloat,
			RightType: TypeDecimal,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDate,
			RightType: TypeDate,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestamp,
			RightType: TypeTimestamp,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestampTZ,
			RightType: TypeTimestampTZ,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestamp,
			RightType: TypeTimestampTZ,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestampTZ,
			RightType: TypeTimestamp,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDate,
			RightType: TypeTimestampTZ,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDate,
			RightType: TypeTimestamp,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestampTZ,
			RightType: TypeDate,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestamp,
			RightType: TypeDate,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeInterval,
			RightType: TypeInterval,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeOid,
			RightType: TypeOid,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTuple,
			RightType: TypeTuple,
			// contains filtered or unexported fields
		},
	},

	LT: {
		CmpOp{
			LeftType:  TypeString,
			RightType: TypeString,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeCollatedString,
			RightType: TypeCollatedString,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeBytes,
			RightType: TypeBytes,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeBool,
			RightType: TypeBool,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeInt,
			RightType: TypeInt,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeFloat,
			RightType: TypeFloat,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDecimal,
			RightType: TypeDecimal,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeFloat,
			RightType: TypeInt,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeInt,
			RightType: TypeFloat,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDecimal,
			RightType: TypeInt,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeInt,
			RightType: TypeDecimal,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDecimal,
			RightType: TypeFloat,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeFloat,
			RightType: TypeDecimal,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDate,
			RightType: TypeDate,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestamp,
			RightType: TypeTimestamp,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestampTZ,
			RightType: TypeTimestampTZ,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestamp,
			RightType: TypeTimestampTZ,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestampTZ,
			RightType: TypeTimestamp,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDate,
			RightType: TypeTimestampTZ,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDate,
			RightType: TypeTimestamp,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestampTZ,
			RightType: TypeDate,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestamp,
			RightType: TypeDate,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeInterval,
			RightType: TypeInterval,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTuple,
			RightType: TypeTuple,
			// contains filtered or unexported fields
		},
	},

	LE: {
		CmpOp{
			LeftType:  TypeString,
			RightType: TypeString,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeCollatedString,
			RightType: TypeCollatedString,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeBytes,
			RightType: TypeBytes,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeBool,
			RightType: TypeBool,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeInt,
			RightType: TypeInt,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeFloat,
			RightType: TypeFloat,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDecimal,
			RightType: TypeDecimal,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeFloat,
			RightType: TypeInt,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeInt,
			RightType: TypeFloat,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDecimal,
			RightType: TypeInt,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeInt,
			RightType: TypeDecimal,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDecimal,
			RightType: TypeFloat,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeFloat,
			RightType: TypeDecimal,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDate,
			RightType: TypeDate,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestamp,
			RightType: TypeTimestamp,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestampTZ,
			RightType: TypeTimestampTZ,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestampTZ,
			RightType: TypeTimestamp,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestamp,
			RightType: TypeTimestampTZ,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDate,
			RightType: TypeTimestampTZ,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDate,
			RightType: TypeTimestamp,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestampTZ,
			RightType: TypeDate,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestamp,
			RightType: TypeDate,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeInterval,
			RightType: TypeInterval,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTuple,
			RightType: TypeTuple,
			// contains filtered or unexported fields
		},
	},

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

	Like: {
		CmpOp{
			LeftType:  TypeString,
			RightType: TypeString,
			// contains filtered or unexported fields
		},
	},

	ILike: {
		CmpOp{
			LeftType:  TypeString,
			RightType: TypeString,
			// contains filtered or unexported fields
		},
	},

	SimilarTo: {
		CmpOp{
			LeftType:  TypeString,
			RightType: TypeString,
			// contains filtered or unexported fields
		},
	},

	RegMatch: {
		CmpOp{
			LeftType:  TypeString,
			RightType: TypeString,
			// contains filtered or unexported fields
		},
	},

	RegIMatch: {
		CmpOp{
			LeftType:  TypeString,
			RightType: TypeString,
			// contains filtered or unexported fields
		},
	},
}

CmpOps contains the comparison operations indexed by operation type.

View Source
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.

OidToType maps Postgres object IDs to CockroachDB types.

View Source
var StarDatumInstance = &StarDatum{}

StarDatumInstance can be used as common instance for all uses of StarDatum.

View Source
var UnaryOps = map[UnaryOperator]unaryOpOverload{
	UnaryPlus: {
		UnaryOp{
			Typ:        TypeInt,
			ReturnType: TypeInt,
			// contains filtered or unexported fields
		},
		UnaryOp{
			Typ:        TypeFloat,
			ReturnType: TypeFloat,
			// contains filtered or unexported fields
		},
		UnaryOp{
			Typ:        TypeDecimal,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
	},

	UnaryMinus: {
		UnaryOp{
			Typ:        TypeInt,
			ReturnType: TypeInt,
			// contains filtered or unexported fields
		},
		UnaryOp{
			Typ:        TypeFloat,
			ReturnType: TypeFloat,
			// contains filtered or unexported fields
		},
		UnaryOp{
			Typ:        TypeDecimal,
			ReturnType: TypeDecimal,
			// contains filtered or unexported fields
		},
		UnaryOp{
			Typ:        TypeInterval,
			ReturnType: TypeInterval,
			// contains filtered or unexported fields
		},
	},

	UnaryComplement: {
		UnaryOp{
			Typ:        TypeInt,
			ReturnType: TypeInt,
			// contains filtered or unexported fields
		},
	},
}

UnaryOps contains the unary operations indexed by operation type.

Functions

func AsString

func AsString(n NodeFormatter) string

AsString pretty prints a node to a string.

func AsStringWithFlags

func AsStringWithFlags(n NodeFormatter, f FmtFlags) string

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

func ContainsVars

func ContainsVars(expr Expr) bool

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

func ExprDebugString

func ExprDebugString(expr Expr) string

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

func FindEqualComparisonFunction

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

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

func HasReturningClause(clause ReturningClause) bool

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

func IsIdentAggregate

func IsIdentAggregate(f AggregateFunc) bool

IsIdentAggregate returns true for identAggregate.

func IsNumericOne

func IsNumericOne(expr TypedExpr) bool

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

func IsNumericZero

func IsNumericZero(expr TypedExpr) bool

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

func PGDisplayName

func PGDisplayName(typ Type) string

PGDisplayName returns the Postgres display name for a given type.

func PGIOBuiltinPrefix

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

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

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

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

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

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

func WalkExprConst(v Visitor, expr Expr)

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

Types

type AggregateFunc

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

func NewIdentAggregate(*EvalContext) AggregateFunc

NewIdentAggregate returns an identAggregate (see comment on struct).

type AliasClause

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

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

Format implements the NodeFormatter interface.

type AliasedTableExpr

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

AliasedTableExpr represents a table expression coupled with an optional alias.

func (*AliasedTableExpr) Format

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

Format implements the NodeFormatter interface.

func (*AliasedTableExpr) String

func (node *AliasedTableExpr) String() string

type AllColumnsSelector

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

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

Eval implements the TypedExpr interface.

func (*AllColumnsSelector) Format

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

Format implements the NodeFormatter interface.

func (*AllColumnsSelector) NormalizeVarName

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

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

func (*AllColumnsSelector) ResolvedType

func (*AllColumnsSelector) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*AllColumnsSelector) String

func (a *AllColumnsSelector) String() string

func (*AllColumnsSelector) TypeCheck

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

TypeCheck implements the Expr interface.

func (*AllColumnsSelector) Variable

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

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

Walk implements the Expr interface.

type AllTablesSelector

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

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

Format implements the NodeFormatter interface.

func (*AllTablesSelector) NormalizeTablePattern

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

NormalizeTablePattern implements the TablePattern interface.

func (*AllTablesSelector) QualifyWithDatabase

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

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

func (*AllTablesSelector) String

func (at *AllTablesSelector) String() string

type AlterTable

type AlterTable struct {
	IfExists bool
	Table    NormalizableTableName
	Cmds     AlterTableCmds
}

AlterTable represents an ALTER TABLE statement.

func (*AlterTable) Format

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

Format implements the NodeFormatter interface.

func (*AlterTable) StatementTag

func (*AlterTable) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*AlterTable) StatementType

func (*AlterTable) StatementType() StatementType

StatementType implements the Statement interface.

func (*AlterTable) String

func (n *AlterTable) String() string

type AlterTableAddColumn

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

AlterTableAddColumn represents an ADD COLUMN command.

func (*AlterTableAddColumn) Format

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

Format implements the NodeFormatter interface.

func (*AlterTableAddColumn) String

func (n *AlterTableAddColumn) String() string

type AlterTableAddConstraint

type AlterTableAddConstraint struct {
	ConstraintDef      ConstraintTableDef
	ValidationBehavior ValidationBehavior
}

AlterTableAddConstraint represents an ADD CONSTRAINT command.

func (*AlterTableAddConstraint) Format

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

Format implements the NodeFormatter interface.

func (*AlterTableAddConstraint) String

func (n *AlterTableAddConstraint) String() string

type AlterTableCmd

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

AlterTableCmd represents a table modification operation.

type AlterTableCmds

type AlterTableCmds []AlterTableCmd

AlterTableCmds represents a list of table alterations.

func (AlterTableCmds) Format

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

Format implements the NodeFormatter interface.

func (AlterTableCmds) String

func (n AlterTableCmds) String() string

type AlterTableDropColumn

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

AlterTableDropColumn represents a DROP COLUMN command.

func (*AlterTableDropColumn) Format

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

Format implements the NodeFormatter interface.

func (*AlterTableDropColumn) String

func (n *AlterTableDropColumn) String() string

type AlterTableDropConstraint

type AlterTableDropConstraint struct {
	IfExists     bool
	Constraint   Name
	DropBehavior DropBehavior
}

AlterTableDropConstraint represents a DROP CONSTRAINT command.

func (*AlterTableDropConstraint) Format

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

Format implements the NodeFormatter interface.

func (*AlterTableDropConstraint) String

func (n *AlterTableDropConstraint) String() string

type AlterTableDropNotNull

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

AlterTableDropNotNull represents an ALTER COLUMN DROP NOT NULL command.

func (*AlterTableDropNotNull) Format

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

Format implements the NodeFormatter interface.

func (*AlterTableDropNotNull) GetColumn

func (node *AlterTableDropNotNull) GetColumn() Name

GetColumn implements the ColumnMutationCmd interface.

func (*AlterTableDropNotNull) String

func (n *AlterTableDropNotNull) String() string

type AlterTableSetDefault

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

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

Format implements the NodeFormatter interface.

func (*AlterTableSetDefault) GetColumn

func (node *AlterTableSetDefault) GetColumn() Name

GetColumn implements the ColumnMutationCmd interface.

func (*AlterTableSetDefault) String

func (n *AlterTableSetDefault) String() string

type AlterTableValidateConstraint

type AlterTableValidateConstraint struct {
	Constraint Name
}

AlterTableValidateConstraint represents a VALIDATE CONSTRAINT command.

func (*AlterTableValidateConstraint) Format

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

Format implements the NodeFormatter interface.

type AndExpr

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

AndExpr represents an AND expression.

func NewTypedAndExpr

func NewTypedAndExpr(left, right TypedExpr) *AndExpr

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

func (*AndExpr) Eval

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

Eval implements the TypedExpr interface.

func (*AndExpr) Format

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

Format implements the NodeFormatter interface.

func (AndExpr) ResolvedType

func (ta AndExpr) ResolvedType() Type

func (*AndExpr) String

func (node *AndExpr) String() string

func (*AndExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*AndExpr) TypedLeft

func (node *AndExpr) TypedLeft() TypedExpr

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

func (*AndExpr) TypedRight

func (node *AndExpr) TypedRight() TypedExpr

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

func (*AndExpr) Walk

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

Walk implements the Expr interface.

type AnnotateTypeExpr

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

AnnotateTypeExpr represents a ANNOTATE_TYPE(expr, type) expression.

func (*AnnotateTypeExpr) Format

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

Format implements the NodeFormatter interface.

func (*AnnotateTypeExpr) String

func (node *AnnotateTypeExpr) String() string

func (*AnnotateTypeExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*AnnotateTypeExpr) TypedInnerExpr

func (node *AnnotateTypeExpr) TypedInnerExpr() TypedExpr

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

func (*AnnotateTypeExpr) Walk

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

Walk implements the Expr interface.

type ArgTypes

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

func (a ArgTypes) Length() int

Length implements the typeList interface.

func (ArgTypes) String

func (a ArgTypes) String() string

func (ArgTypes) Types

func (a ArgTypes) Types() []Type

Types implements the typeList interface.

type Array

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

Array represents an array constructor.

func (*Array) Eval

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

Eval implements the TypedExpr interface.

func (*Array) Format

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

Format implements the NodeFormatter interface.

func (Array) ResolvedType

func (ta Array) ResolvedType() Type

func (*Array) String

func (node *Array) String() string

func (*Array) TypeCheck

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

TypeCheck implements the Expr interface.

func (*Array) Walk

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

Walk implements the Expr interface.

type ArrayColType

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

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

Format implements the NodeFormatter interface.

func (*ArrayColType) String

func (node *ArrayColType) String() string

type ArrayFlatten

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

ArrayFlatten represents a subquery array constructor.

func (*ArrayFlatten) Eval

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

Eval implements the TypedExpr interface.

func (*ArrayFlatten) Format

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

Format implements the NodeFormatter interface.

func (ArrayFlatten) ResolvedType

func (ta ArrayFlatten) ResolvedType() Type

func (*ArrayFlatten) String

func (node *ArrayFlatten) String() string

func (*ArrayFlatten) TypeCheck

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

TypeCheck implements the Expr interface.

func (*ArrayFlatten) Walk

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

Walk implements the Expr interface.

type ArraySubscript

type ArraySubscript struct {
	Begin Expr
	End   Expr
	Slice bool
}

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

func (*ArraySubscript) Format

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

Format implements the NodeFormatter interface.

type ArraySubscripts

type ArraySubscripts []*ArraySubscript

ArraySubscripts represents a sequence of one or more array subscripts.

func (ArraySubscripts) Format

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

Format implements the NodeFormatter interface.

type AsOfClause

type AsOfClause struct {
	Expr Expr
}

AsOfClause represents an as of time.

func (AsOfClause) Format

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

Format implements the NodeFormatter interface.

type Backup

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

Backup represents a BACKUP statement.

func (*Backup) Format

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

Format implements the NodeFormatter interface.

func (*Backup) StatementTag

func (*Backup) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Backup) StatementType

func (*Backup) StatementType() StatementType

StatementType implements the Statement interface.

func (*Backup) String

func (n *Backup) String() string

type BeginTransaction

type BeginTransaction struct {
	Isolation    IsolationLevel
	UserPriority UserPriority
}

BeginTransaction represents a BEGIN statement

func (*BeginTransaction) Format

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

Format implements the NodeFormatter interface.

func (*BeginTransaction) StatementTag

func (*BeginTransaction) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*BeginTransaction) StatementType

func (*BeginTransaction) StatementType() StatementType

StatementType implements the Statement interface.

func (*BeginTransaction) String

func (n *BeginTransaction) String() string

type BinOp

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

BinOp is a binary operator.

type BinaryExpr

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

BinaryExpr represents a binary value expression.

func (*BinaryExpr) Eval

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

Eval implements the TypedExpr interface.

func (*BinaryExpr) Format

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

Format implements the NodeFormatter interface.

func (BinaryExpr) ResolvedType

func (ta BinaryExpr) ResolvedType() Type

func (*BinaryExpr) String

func (node *BinaryExpr) String() string

func (*BinaryExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*BinaryExpr) TypedLeft

func (node *BinaryExpr) TypedLeft() TypedExpr

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

func (*BinaryExpr) TypedRight

func (node *BinaryExpr) TypedRight() TypedExpr

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

func (*BinaryExpr) Walk

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

Walk implements the Expr interface.

type BinaryOperator

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

func (i BinaryOperator) String() string

type BoolColType

type BoolColType struct {
	Name string
}

BoolColType represents a BOOLEAN type.

func (*BoolColType) Format

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

Format implements the NodeFormatter interface.

func (*BoolColType) String

func (node *BoolColType) String() string

type Builtin

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

func (b Builtin) Category() string

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

func (Builtin) Class

func (b Builtin) Class() FunctionClass

Class returns the FunctionClass of this builtin.

func (Builtin) DistSQLBlacklist

func (b Builtin) DistSQLBlacklist() bool

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

func (Builtin) FixedReturnType

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) Impure

func (b Builtin) Impure() bool

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

func (Builtin) Signature

func (b Builtin) Signature() string

Signature returns a human-readable signature.

type BytesColType

type BytesColType struct {
	Name string
}

BytesColType represents a BYTES or BLOB type.

func (*BytesColType) Format

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

Format implements the NodeFormatter interface.

func (*BytesColType) String

func (node *BytesColType) String() string

type CaseExpr

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

CaseExpr represents a CASE expression.

func (*CaseExpr) CopyNode

func (expr *CaseExpr) CopyNode() *CaseExpr

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

func (*CaseExpr) Eval

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

Eval implements the TypedExpr interface.

func (*CaseExpr) Format

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

Format implements the NodeFormatter interface.

func (CaseExpr) ResolvedType

func (ta CaseExpr) ResolvedType() Type

func (*CaseExpr) String

func (node *CaseExpr) String() string

func (*CaseExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*CaseExpr) Walk

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

Walk implements the Expr interface.

type CastExpr

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

CastExpr represents a CAST(expr AS type) expression.

func (*CastExpr) Eval

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

Eval implements the TypedExpr interface.

func (*CastExpr) Format

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

Format implements the NodeFormatter interface.

func (CastExpr) ResolvedType

func (ta CastExpr) ResolvedType() Type

func (*CastExpr) String

func (node *CastExpr) String() string

func (*CastExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*CastExpr) Walk

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

Walk implements the Expr interface.

type CastTargetType

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

CastTargetType represents a type that is a valid cast target.

func ParseType added in v1.0.3

func ParseType(sql string) (CastTargetType, error)

ParseType parses a column type.

type CheckConstraintTableDef

type CheckConstraintTableDef struct {
	Name Name
	Expr Expr
}

CheckConstraintTableDef represents a check constraint within a CREATE TABLE statement.

func (*CheckConstraintTableDef) Format

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

Format implements the NodeFormatter interface.

type CmpOp

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

CmpOp is a comparison operator.

type CoalesceExpr

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

CoalesceExpr represents a COALESCE or IFNULL expression.

func (*CoalesceExpr) CopyNode

func (expr *CoalesceExpr) CopyNode() *CoalesceExpr

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

func (*CoalesceExpr) Eval

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

Eval implements the TypedExpr interface.

func (*CoalesceExpr) Format

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

Format implements the NodeFormatter interface.

func (CoalesceExpr) ResolvedType

func (ta CoalesceExpr) ResolvedType() Type

func (*CoalesceExpr) String

func (node *CoalesceExpr) String() string

func (*CoalesceExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*CoalesceExpr) TypedExprAt

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

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

func (*CoalesceExpr) Walk

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

Walk implements the Expr interface.

type CollateExpr

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

CollateExpr represents an (expr COLLATE locale) expression.

func (*CollateExpr) Eval

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

Eval implements the TypedExpr interface.

func (*CollateExpr) Format

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

Format implements the NodeFormatter interface.

func (CollateExpr) ResolvedType

func (ta CollateExpr) ResolvedType() Type

func (*CollateExpr) String

func (node *CollateExpr) String() string

func (*CollateExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*CollateExpr) Walk

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

Walk implements the Expr interface.

type CollatedStringColType

type CollatedStringColType struct {
	Name   string
	N      int
	Locale string
}

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

func (*CollatedStringColType) Format

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

Format implements the NodeFormatter interface.

func (*CollatedStringColType) String

func (node *CollatedStringColType) String() string

type CollationEnvironment

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

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

type ColumnCheckConstraint

type ColumnCheckConstraint struct {
	Expr Expr
}

ColumnCheckConstraint represents either a check on a column.

type ColumnCollation

type ColumnCollation string

ColumnCollation represents a COLLATE clause for a column.

type ColumnDefault

type ColumnDefault struct {
	Expr Expr
}

ColumnDefault represents a DEFAULT clause for a column.

type ColumnFKConstraint

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

ColumnFKConstraint represents a FK-constaint on a column.

type ColumnFamilyConstraint

type ColumnFamilyConstraint struct {
	Family      Name
	Create      bool
	IfNotExists bool
}

ColumnFamilyConstraint represents FAMILY on a column.

type ColumnID

type ColumnID uint32

ColumnID is a custom type for ColumnDescriptor IDs.

type ColumnItem

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

func (c *ColumnItem) Column() string

Column retrieves the unqualified column name.

func (*ColumnItem) Eval

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

Eval implements the TypedExpr interface.

func (*ColumnItem) Format

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

Format implements the NodeFormatter interface.

func (*ColumnItem) NormalizeVarName

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

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

func (*ColumnItem) ResolvedType

func (c *ColumnItem) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*ColumnItem) String

func (c *ColumnItem) String() string

func (*ColumnItem) TypeCheck

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

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

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

Walk implements the Expr interface.

type ColumnMutationCmd

type ColumnMutationCmd interface {
	AlterTableCmd
	GetColumn() Name
}

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

type ColumnQualification

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

ColumnQualification represents a constraint on a column.

type ColumnTableDef

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

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

Format implements the NodeFormatter interface.

func (*ColumnTableDef) HasColumnFamily

func (node *ColumnTableDef) HasColumnFamily() bool

HasColumnFamily returns if the ColumnTableDef has a column family.

func (*ColumnTableDef) HasDefaultExpr

func (node *ColumnTableDef) HasDefaultExpr() bool

HasDefaultExpr returns if the ColumnTableDef has a default expression.

func (*ColumnTableDef) HasFKConstraint

func (node *ColumnTableDef) HasFKConstraint() bool

HasFKConstraint returns if the ColumnTableDef has a foreign key constraint.

type ColumnTableDefCheckExpr

type ColumnTableDefCheckExpr struct {
	Expr           Expr
	ConstraintName Name
}

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

type ColumnType

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

ColumnType represents a type in a column definition.

func DatumTypeToColumnType

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

type CommitTransaction struct{}

CommitTransaction represents a COMMIT statement.

func (*CommitTransaction) Format

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

Format implements the NodeFormatter interface.

func (*CommitTransaction) StatementTag

func (*CommitTransaction) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CommitTransaction) StatementType

func (*CommitTransaction) StatementType() StatementType

StatementType implements the Statement interface.

func (*CommitTransaction) String

func (n *CommitTransaction) String() string

type ComparisonExpr

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

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

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

func (*ComparisonExpr) Eval

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

Eval implements the TypedExpr interface.

func (*ComparisonExpr) Format

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

Format implements the NodeFormatter interface.

func (*ComparisonExpr) IsMixedTypeComparison

func (node *ComparisonExpr) IsMixedTypeComparison() bool

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

func (ComparisonExpr) ResolvedType

func (ta ComparisonExpr) ResolvedType() Type

func (*ComparisonExpr) String

func (node *ComparisonExpr) String() string

func (*ComparisonExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*ComparisonExpr) TypedLeft

func (node *ComparisonExpr) TypedLeft() TypedExpr

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

func (*ComparisonExpr) TypedRight

func (node *ComparisonExpr) TypedRight() TypedExpr

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

func (*ComparisonExpr) Walk

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

Walk implements the Expr interface.

type ComparisonOperator

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

func (i ComparisonOperator) String() string

type CompositeDatum

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

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

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

ConstraintTableDef represents a constraint definition within a CREATE TABLE statement.

type ContainsWindowVisitor

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

ContainsWindowVisitor checks if walked expressions contain window functions.

func (*ContainsWindowVisitor) ContainsWindowFunc

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

ContainsWindowFunc determines if an Expr contains a window function.

func (*ContainsWindowVisitor) VisitPost

func (*ContainsWindowVisitor) VisitPost(expr Expr) Expr

VisitPost satisfies the Visitor interface.

func (*ContainsWindowVisitor) VisitPre

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

VisitPre satisfies the Visitor interface.

type CopyFrom

type CopyFrom struct {
	Table   NormalizableTableName
	Columns UnresolvedNames
	Stdin   bool
}

CopyFrom represents a COPY FROM statement.

func (*CopyFrom) Format

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

Format implements the NodeFormatter interface.

func (*CopyFrom) StatementTag

func (*CopyFrom) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CopyFrom) StatementType

func (*CopyFrom) StatementType() StatementType

StatementType implements the Statement interface.

func (*CopyFrom) String

func (n *CopyFrom) String() string

type CreateDatabase

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

CreateDatabase represents a CREATE DATABASE statement.

func (*CreateDatabase) Format

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

Format implements the NodeFormatter interface.

func (*CreateDatabase) StatementTag

func (*CreateDatabase) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CreateDatabase) StatementType

func (*CreateDatabase) StatementType() StatementType

StatementType implements the Statement interface.

func (*CreateDatabase) String

func (n *CreateDatabase) String() string

type CreateIndex

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

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

Format implements the NodeFormatter interface.

func (*CreateIndex) StatementTag

func (*CreateIndex) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CreateIndex) StatementType

func (*CreateIndex) StatementType() StatementType

StatementType implements the Statement interface.

func (*CreateIndex) String

func (n *CreateIndex) String() string

type CreateTable

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

func (node *CreateTable) As() bool

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

func (*CreateTable) Format

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

Format implements the NodeFormatter interface.

func (*CreateTable) StatementTag

func (n *CreateTable) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CreateTable) StatementType

func (*CreateTable) StatementType() StatementType

StatementType implements the Statement interface.

func (*CreateTable) String

func (n *CreateTable) String() string

type CreateUser

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

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

Format implements the NodeFormatter interface.

func (*CreateUser) HasPassword

func (node *CreateUser) HasPassword() bool

HasPassword returns if the CreateUser has a password.

func (*CreateUser) StatementTag

func (*CreateUser) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CreateUser) StatementType

func (*CreateUser) StatementType() StatementType

StatementType implements the Statement interface.

func (*CreateUser) String

func (n *CreateUser) String() string

type CreateView

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

CreateView represents a CREATE VIEW statement.

func (*CreateView) Format

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

Format implements the NodeFormatter interface.

func (*CreateView) StatementTag

func (*CreateView) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CreateView) StatementType

func (*CreateView) StatementType() StatementType

StatementType implements the Statement interface.

func (*CreateView) String

func (n *CreateView) String() string

type DArray

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

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

func MustBeDArray(e Expr) *DArray

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

func NewDArray

func NewDArray(paramTyp Type) *DArray

NewDArray returns a DArray containing elements of the specified type.

func (*DArray) AmbiguousFormat

func (*DArray) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DArray) Append

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

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

Compare implements the Datum interface.

func (*DArray) Eval

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

Eval implements the TypedExpr interface.

func (*DArray) Format

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

Format implements the NodeFormatter interface.

func (*DArray) IsMax

func (d *DArray) IsMax() bool

IsMax implements the Datum interface.

func (*DArray) IsMin

func (d *DArray) IsMin() bool

IsMin implements the Datum interface.

func (*DArray) Len

func (d *DArray) Len() int

Len returns the length of the Datum array.

func (*DArray) Next

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

Next implements the Datum interface.

func (*DArray) Prev

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

Prev implements the Datum interface.

func (*DArray) ResolvedType

func (d *DArray) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DArray) Size

func (d *DArray) Size() uintptr

Size implements the Datum interface.

func (*DArray) String

func (node *DArray) String() string

func (*DArray) TypeCheck

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

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

Walk implements the Expr interface.

type DBool

type DBool bool

DBool is the boolean Datum.

func GetBool

func GetBool(d Datum) (DBool, error)

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

func MakeDBool

func MakeDBool(d DBool) *DBool

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

func ParseDBool

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

func (*DBool) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DBool) Compare

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

Compare implements the Datum interface.

func (*DBool) Eval

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

Eval implements the TypedExpr interface.

func (*DBool) Format

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

Format implements the NodeFormatter interface.

func (*DBool) IsMax

func (d *DBool) IsMax() bool

IsMax implements the Datum interface.

func (*DBool) IsMin

func (d *DBool) IsMin() bool

IsMin implements the Datum interface.

func (*DBool) Next

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

Next implements the Datum interface.

func (*DBool) Prev

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

Prev implements the Datum interface.

func (*DBool) ResolvedType

func (*DBool) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DBool) Size

func (d *DBool) Size() uintptr

Size implements the Datum interface.

func (*DBool) String

func (node *DBool) String() string

func (*DBool) TypeCheck

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

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

Walk implements the Expr interface.

type DBytes

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

func NewDBytes(d DBytes) *DBytes

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

func (*DBytes) AmbiguousFormat

func (*DBytes) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DBytes) Compare

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

Compare implements the Datum interface.

func (*DBytes) Eval

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

Eval implements the TypedExpr interface.

func (*DBytes) Format

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

Format implements the NodeFormatter interface.

func (*DBytes) IsMax

func (*DBytes) IsMax() bool

IsMax implements the Datum interface.

func (*DBytes) IsMin

func (d *DBytes) IsMin() bool

IsMin implements the Datum interface.

func (*DBytes) Next

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

Next implements the Datum interface.

func (*DBytes) Prev

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

Prev implements the Datum interface.

func (*DBytes) ResolvedType

func (*DBytes) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DBytes) Size

func (d *DBytes) Size() uintptr

Size implements the Datum interface.

func (*DBytes) String

func (node *DBytes) String() string

func (*DBytes) TypeCheck

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

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

Walk implements the Expr interface.

type DCollatedString

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

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

func (*DCollatedString) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DCollatedString)