parser

package
Version: v0.0.0-...-4f9c864 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2017 License: Apache-2.0 Imports: 43 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 = 57642
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 COALESCE = 57396
View Source
const COLLATE = 57397
View Source
const COLLATION = 57398
View Source
const COLUMN = 57399
View Source
const COLUMNS = 57400
View Source
const COMMIT = 57401
View Source
const COMMITTED = 57402
View Source
const CONCAT = 57403
View Source
const CONFLICT = 57404
View Source
const CONSTRAINT = 57405
View Source
const CONSTRAINTS = 57406
View Source
const COPY = 57407
View Source
const COVERING = 57408
View Source
const CREATE = 57409
View Source
const CROSS = 57410
View Source
const CUBE = 57411
View Source
const CURRENT = 57412
View Source
const CURRENT_CATALOG = 57413
View Source
const CURRENT_DATE = 57414
View Source
const CURRENT_ROLE = 57415
View Source
const CURRENT_TIME = 57416
View Source
const CURRENT_TIMESTAMP = 57417
View Source
const CURRENT_USER = 57418
View Source
const CYCLE = 57419
View Source
const DATA = 57420
View Source
const DATABASE = 57421
View Source
const DATABASES = 57422
View Source
const DATE = 57423
View Source
const DAY = 57424
View Source
const DEALLOCATE = 57428
View Source
const DEC = 57425
View Source
const DECIMAL = 57426
View Source
const DEFAULT = 57427
View Source
const DEFERRABLE = 57429
View Source
const DELETE = 57430
View Source
const DESC = 57431
View Source
const DISTINCT = 57432
View Source
const DO = 57433
View Source
const DOT_DOT = 57354
View Source
const DOUBLE = 57434
View Source
const DROP = 57435
View Source
const ELSE = 57436
View Source
const ENCODING = 57437
View Source
const END = 57438
View Source
const ERROR = 57361
View Source
const ESCAPE = 57439
View Source
const EXCEPT = 57440
View Source
const EXECUTE = 57442
View Source
const EXISTS = 57441
View Source
const EXPLAIN = 57443
View Source
const EXTRACT = 57444
View Source
const EXTRACT_DURATION = 57445
View Source
const FALSE = 57446
View Source
const FAMILY = 57447
View Source
const FCONST = 57350
View Source
const FETCH = 57448
View Source
const FILTER = 57449
View Source
const FIRST = 57450
View Source
const FLOAT = 57451
View Source
const FLOORDIV = 57452
View Source
const FOLLOWING = 57453
View Source
const FOR = 57454
View Source
const FORCE_INDEX = 57455
View Source
const FOREIGN = 57456
View Source
const FROM = 57457
View Source
const FULL = 57458
View Source
const GRANT = 57459
View Source
const GRANTS = 57460
View Source
const GREATER_EQUALS = 57356
View Source
const GREATEST = 57461
View Source
const GROUP = 57462
View Source
const GROUPING = 57463
View Source
const HAVING = 57464
View Source
const HELP = 57465
View Source
const HIGH = 57466
View Source
const HOUR = 57467
View Source
const ICONST = 57349
View Source
const IDENT = 57346
View Source
const IF = 57469
View Source
const IFNULL = 57470
View Source
const ILIKE = 57471
View Source
const IN = 57472
View Source
const INCREMENTAL = 57468
View Source
const INDEX = 57474
View Source
const INDEXES = 57475
View Source
const INITIALLY = 57476
View Source
const INNER = 57477
View Source
const INSERT = 57478
View Source
const INT = 57479
View Source
const INT64 = 57481
View Source
const INT8 = 57480
View Source
const INTEGER = 57482
View Source
const INTERLEAVE = 57473
View Source
const INTERSECT = 57483
View Source
const INTERVAL = 57484
View Source
const INTO = 57485
View Source
const IS = 57486
View Source
const ISOLATION = 57487
View Source
const InvalidColIdx = -1

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

View Source
const JOIN = 57488
View Source
const KEY = 57489
View Source
const KEYS = 57490
View Source
const LATERAL = 57491
View Source
const LC_COLLATE = 57493
View Source
const LC_CTYPE = 57492
View Source
const LEADING = 57494
View Source
const LEAST = 57495
View Source
const LEFT = 57496
View Source
const LESS_EQUALS = 57355
View Source
const LEVEL = 57497
View Source
const LIKE = 57498
View Source
const LIMIT = 57499
View Source
const LOCAL = 57500
View Source
const LOCALTIME = 57501
View Source
const LOCALTIMESTAMP = 57502
View Source
const LOW = 57503
View Source
const LSHIFT = 57504
View Source
const MATCH = 57505
View Source
const MINUTE = 57506
View Source
const MONTH = 57507
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 = 57508
View Source
const NAMES = 57509
View Source
const NATURAL = 57510
View Source
const NEXT = 57511
View Source
const NO = 57512
View Source
const NORMAL = 57514
View Source
const NOT = 57515
View Source
const NOTHING = 57516
View Source
const NOT_EQUALS = 57357
View Source
const NOT_LA = 57640
View Source
const NOT_REGIMATCH = 57360
View Source
const NOT_REGMATCH = 57358
View Source
const NO_INDEX_JOIN = 57513
View Source
const NULL = 57517
View Source
const NULLIF = 57518
View Source
const NULLS = 57519
View Source
const NUMERIC = 57520
View Source
const OF = 57521
View Source
const OFF = 57522
View Source
const OFFSET = 57523
View Source
const OID = 57524
View Source
const ON = 57525
View Source
const ONLY = 57526
View Source
const OPTIONS = 57527
View Source
const OR = 57528
View Source
const ORDER = 57529
View Source
const ORDINALITY = 57530
View Source
const OUT = 57531
View Source
const OUTER = 57532
View Source
const OVER = 57533
View Source
const OVERLAPS = 57534
View Source
const OVERLAY = 57535
View Source
const PARENT = 57536
View Source
const PARTIAL = 57537
View Source
const PARTITION = 57538
View Source
const PASSWORD = 57539
View Source
const PLACEHOLDER = 57351
View Source
const PLACING = 57540
View Source
const POSITION = 57541
View Source
const POSTFIXOP = 57643
View Source
const PRECEDING = 57542
View Source
const PRECISION = 57543
View Source
const PREPARE = 57544
View Source
const PRIMARY = 57545
View Source
const PRIORITY = 57546
View Source
const RANGE = 57547
View Source
const READ = 57548
View Source
const REAL = 57549
View Source
const RECURSIVE = 57550
View Source
const REF = 57551
View Source
const REFERENCES = 57552
View Source
const REGCLASS = 57553
View Source
const REGIMATCH = 57359
View Source
const REGNAMESPACE = 57556
View Source
const REGPROC = 57554
View Source
const REGPROCEDURE = 57555
View Source
const REGTYPE = 57557
View Source
const RELEASE = 57560
View Source
const RENAME = 57558
View Source
const REPEATABLE = 57559
View Source
const RESTORE = 57561
View Source
const RESTRICT = 57562
View Source
const RETURNING = 57563
View Source
const REVOKE = 57564
View Source
const RIGHT = 57565
View Source
const ROLLBACK = 57566
View Source
const ROLLUP = 57567
View Source
const ROW = 57568
View Source
const ROWS = 57569
View Source
const RSHIFT = 57570
View Source
const RestartSavepointName string = "COCKROACH_RESTART"

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

View Source
const SAVEPOINT = 57572
View Source
const SCONST = 57347
View Source
const SEARCH = 57573
View Source
const SECOND = 57574
View Source
const SELECT = 57575
View Source
const SERIAL = 57576
View Source
const SERIALIZABLE = 57577
View Source
const SESSION = 57578
View Source
const SESSION_USER = 57579
View Source
const SET = 57580
View Source
const SHOW = 57581
View Source
const SIMILAR = 57582
View Source
const SIMPLE = 57583
View Source
const SMALLINT = 57584
View Source
const SMALLSERIAL = 57585
View Source
const SNAPSHOT = 57586
View Source
const SOME = 57587
View Source
const SPLIT = 57588
View Source
const SQL = 57589
View Source
const START = 57590
View Source
const STATUS = 57571
View Source
const STDIN = 57591
View Source
const STORING = 57594
View Source
const STRICT = 57592
View Source
const STRING = 57593
View Source
const SUBSTRING = 57595
View Source
const SYMMETRIC = 57596
View Source
const SYSTEM = 57597
View Source
const TABLE = 57598
View Source
const TABLES = 57599
View Source
const TEMPLATE = 57600
View Source
const TEXT = 57601
View Source
const THEN = 57602
View Source
const TIME = 57603
View Source
const TIMESTAMP = 57604
View Source
const TIMESTAMPTZ = 57605
View Source
const TO = 57606
View Source
const TRAILING = 57607
View Source
const TRANSACTION = 57608
View Source
const TREAT = 57609
View Source
const TRIM = 57610
View Source
const TRUE = 57611
View Source
const TRUNCATE = 57612
View Source
const TYPE = 57613
View Source
const TYPEANNOTATE = 57353
View Source
const TYPECAST = 57352
View Source
const (
	TimestampNodeFormat = timestampFormat + ".999999-07:00"
)

time.Time formats.

View Source
const UMINUS = 57644
View Source
const UNBOUNDED = 57614
View Source
const UNCOMMITTED = 57615
View Source
const UNION = 57616
View Source
const UNIQUE = 57617
View Source
const UNKNOWN = 57618
View Source
const UPDATE = 57619
View Source
const UPSERT = 57620
View Source
const USER = 57621
View Source
const USERS = 57622
View Source
const USING = 57623
View Source
const VALID = 57624
View Source
const VALIDATE = 57625
View Source
const VALUE = 57626
View Source
const VALUES = 57627
View Source
const VARCHAR = 57628
View Source
const VARIADIC = 57629
View Source
const VARYING = 57631
View Source
const VIEW = 57630
View Source
const WHEN = 57632
View Source
const WHERE = 57633
View Source
const WINDOW = 57634
View Source
const WITH = 57635
View Source
const WITHIN = 57636
View Source
const WITHOUT = 57637
View Source
const WITH_LA = 57641
View Source
const YEAR = 57638
View Source
const ZONE = 57639

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{}
)
View Source
var Aggregates = map[string][]Builtin{
	"array_agg": {
		makeAggBuiltin(TypeInt, TypeIntArray, newIntArrayAggregate,
			"Aggregates the selected values into an array."),
		makeAggBuiltin(
			TypeString, TypeStringArray, newStringArrayAggregate,
			"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": countImpls(),

	"max": makeAggBuiltins(newMaxAggregate, "Identifies the maximum selected value.",
		TypeBool, TypeInt, TypeFloat, TypeDecimal, TypeString, TypeBytes,
		TypeDate, TypeTimestamp, TypeTimestampTZ, TypeInterval),
	"min": makeAggBuiltins(newMinAggregate, "Identifies the minimum selected value.",
		TypeBool, TypeInt, TypeFloat, TypeDecimal, TypeString, TypeBytes,
		TypeDate, TypeTimestamp, TypeTimestampTZ, TypeInterval),

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

	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
		},
	},

	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
		},
	},
}

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: TypeString,

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

	"concat_ws": {
		Builtin{
			Types:      VariadicType{TypeString},
			ReturnType: 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:      NamedArgTypes{{"val", TypeString}},
			ReturnType: TypeBytes,

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

	"from_uuid": {
		Builtin{
			Types:      NamedArgTypes{{"val", TypeBytes}},
			ReturnType: TypeString,

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

	"from_ip": {
		Builtin{
			Types:      NamedArgTypes{{"val", TypeBytes}},
			ReturnType: TypeString,

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

	"to_ip": {
		Builtin{
			Types:      NamedArgTypes{{"val", TypeString}},
			ReturnType: TypeBytes,

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

	"split_part": {
		Builtin{
			Types: NamedArgTypes{
				{"input", TypeString},
				{"delimiter", TypeString},
				{"return_index_pos", TypeInt},
			},
			ReturnType: 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:      NamedArgTypes{{"input", TypeString}, {"repeat_counter", TypeInt}},
			ReturnType: 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:      NamedArgTypes{{"val", TypeInt}},
			ReturnType: 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 NewDInt(0), 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: NamedArgTypes{
				{"input", TypeString},
				{"overlay_val", TypeString},
				{"start_pos", TypeInt},
			},
			ReturnType: 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: NamedArgTypes{
				{"input", TypeString},
				{"overlay_val", TypeString},
				{"start_pos", TypeInt},
				{"end_pos", TypeInt},
			},
			ReturnType: 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:      NamedArgTypes{{"input", TypeString}, {"regex", TypeString}},
			ReturnType: TypeString,

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

	"regexp_replace": {
		Builtin{
			Types: NamedArgTypes{
				{"input", TypeString},
				{"regex", TypeString},
				{"replace", TypeString},
			},
			ReturnType: TypeString,

			Info: "Replaces matches for the Regular Expression `regex` in `input` with the " +
				"Regular Expression `replace`.",
			// contains filtered or unexported fields
		},
		Builtin{
			Types: NamedArgTypes{
				{"input", TypeString},
				{"regex", TypeString},
				{"replace", TypeString},
				{"flags", TypeString},
			},
			ReturnType: 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:      NamedArgTypes{{"input", TypeBytes}, {"return_set", TypeInt}},
			ReturnType: TypeBytes,

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

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

	"right": {
		Builtin{
			Types:      NamedArgTypes{{"input", TypeBytes}, {"return_set", TypeInt}},
			ReturnType: TypeBytes,

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

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

	"random": {
		Builtin{
			Types:      NamedArgTypes{},
			ReturnType: TypeFloat,

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

	"unique_rowid": {
		Builtin{
			Types:      NamedArgTypes{},
			ReturnType: 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:      AnyType{},
			ReturnType: TypeAny,

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

	"least": {
		Builtin{
			Types:      AnyType{},
			ReturnType: TypeAny,

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

	"experimental_strftime": {
		Builtin{
			Types:      NamedArgTypes{{"input", TypeTimestamp}, {"extract_format", TypeString}},
			ReturnType: 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:      NamedArgTypes{{"input", TypeDate}, {"extract_format", TypeString}},
			ReturnType: 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:      NamedArgTypes{{"input", TypeTimestampTZ}, {"extract_format", TypeString}},
			ReturnType: 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:      NamedArgTypes{{"format", TypeString}, {"input", TypeString}},
			ReturnType: TypeTimestampTZ,

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

	"age": {
		Builtin{
			Types:      NamedArgTypes{{"val", TypeTimestampTZ}},
			ReturnType: TypeInterval,

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

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

	"current_date": {
		Builtin{
			Types:      NamedArgTypes{},
			ReturnType: TypeDate,

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

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

	"statement_timestamp": {
		Builtin{
			Types:      NamedArgTypes{},
			ReturnType: TypeTimestampTZ,

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

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

	"cluster_logical_timestamp": {
		Builtin{
			Types:      NamedArgTypes{},
			ReturnType: TypeDecimal,

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

	"clock_timestamp": {
		Builtin{
			Types:      NamedArgTypes{},
			ReturnType: TypeTimestampTZ,

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

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

	"extract": {
		Builtin{
			Types:      NamedArgTypes{{"element", TypeString}, {"input", TypeTimestamp}},
			ReturnType: 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:      NamedArgTypes{{"element", TypeString}, {"input", TypeDate}},
			ReturnType: 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:      NamedArgTypes{{"element", TypeString}, {"input", TypeInterval}},
			ReturnType: 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 *inf.Dec) (Datum, error) {
			dd := &DDecimal{}
			dd.Abs(x)
			return dd, nil
		}, "Calculates the absolute value of `val`."),
		Builtin{
			Types:      NamedArgTypes{{"val", TypeInt}},
			ReturnType: 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 *inf.Dec) (Datum, error) {
			dd := &DDecimal{}
			decimal.Cbrt(&dd.Dec, x, decimal.Precision)
			return dd, nil
		}, "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 *inf.Dec) (Datum, error) {
			if y.Sign() == 0 {
				return nil, errDivByZero
			}
			dd := &DDecimal{}
			dd.QuoRound(x, y, 0, inf.RoundDown)
			return dd, nil
		}, "Calculates the integer quotient of `x`/`y`."),
		{
			Types:      NamedArgTypes{{"x", TypeInt}, {"y", TypeInt}},
			ReturnType: 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 *inf.Dec) (Datum, error) {
			return expDecimal(x)
		}, "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 *inf.Dec) (Datum, error) {
			dd := &DDecimal{}
			dd.Round(x, 0, inf.RoundFloor)
			return dd, nil
		}, "Calculates the largest integer not greater than `val`."),
	},

	"ln": {
		floatBuiltin1(func(x float64) (Datum, error) {
			return NewDFloat(DFloat(math.Log(x))), nil
		}, "Calculates the natural log of `val`."),
		decimalLogFn(decimal.Log, "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(decimal.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 *inf.Dec) (Datum, error) {
			if y.Sign() == 0 {
				return nil, errZeroModulus
			}
			dd := &DDecimal{}
			decimal.Mod(&dd.Dec, x, y)
			return dd, nil
		}, "Calculates `x`%`y`."),
		Builtin{
			Types:      NamedArgTypes{{"x", TypeInt}, {"y", TypeInt}},
			ReturnType: TypeInt,

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

	"pi": {
		Builtin{
			Types:      NamedArgTypes{},
			ReturnType: 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 round(x, 0)
		}, "Rounds `val` to the nearest integer."),
		decimalBuiltin1(func(x *inf.Dec) (Datum, error) {
			return roundDecimal(x, 0)
		}, "Rounds `val` to the nearest integer."),
		Builtin{
			Types:      NamedArgTypes{{"input", TypeFloat}, {"decimal_accuracy", TypeInt}},
			ReturnType: TypeFloat,

			Info: "Keeps `decimal_accuracy` number of figures to the right of the zero position " +
				" in `input`.",
			// contains filtered or unexported fields
		},
		Builtin{
			Types:      NamedArgTypes{{"input", TypeDecimal}, {"decimal_accuracy", TypeInt}},
			ReturnType: TypeDecimal,

			Info: "Keeps `decimal_accuracy` number of figures to the right of the zero position " +
				" in `input`.",
			// 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 *inf.Dec) (Datum, error) {
			d := &DDecimal{}
			d.Dec.SetUnscaled(int64(x.Sign()))
			return d, nil
		}, "Determines the sign of `val`: **1** for positive; **0** for 0 values; **-1** for "+
			"negative."),
		Builtin{
			Types:      NamedArgTypes{{"val", TypeInt}},
			ReturnType: 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 *inf.Dec) (Datum, error) {
			if x.Sign() < 0 {
				return nil, errSqrtOfNegNumber
			}
			dd := &DDecimal{}
			decimal.Sqrt(&dd.Dec, x, decimal.Precision)
			return dd, nil
		}, "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 *inf.Dec) (Datum, error) {
			dd := &DDecimal{}
			dd.Round(x, 0, inf.RoundDown)
			return dd, nil
		}, "Truncates the decimal values of `val`."),
	},

	"array_length": {
		Builtin{
			Types:      NamedArgTypes{{"input", TypeAnyArray}, {"array_dimension", TypeInt}},
			ReturnType: 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:      NamedArgTypes{{"input", TypeAnyArray}, {"array_dimension", TypeInt}},
			ReturnType: 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:      NamedArgTypes{{"input", TypeAnyArray}, {"array_dimension", TypeInt}},
			ReturnType: 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:      NamedArgTypes{},
			ReturnType: TypeString,

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

	"current_schema": {
		Builtin{
			Types:      NamedArgTypes{},
			ReturnType: TypeString,

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

	"current_schemas": {
		Builtin{
			Types:      NamedArgTypes{{"include_implicit", TypeBool}},
			ReturnType: TypeStringArray,

			Info: "Returns the current database; optionally include implicit schemas (e.g. " +
				"`pg_catalog`).",
			// contains filtered or unexported fields
		},
	},

	"crdb_internal.force_retry": {
		Builtin{
			Types:      NamedArgTypes{{"val", TypeInterval}},
			ReturnType: TypeInt,

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

	"pg_catalog.pg_get_expr": {
		Builtin{
			Types: NamedArgTypes{
				{"pg_node_tree", TypeString},
				{"relation_oid", TypeInt},
			},
			ReturnType: TypeString,

			Info: "Not usable; supported only for ORM compatibility",
			// contains filtered or unexported fields
		},
		Builtin{
			Types: NamedArgTypes{
				{"pg_node_tree", TypeString},
				{"relation_oid", TypeInt},
				{"pretty_bool", TypeBool},
			},
			ReturnType: TypeString,

			Info: "Not usable; supported only for ORM compatibility",
			// contains filtered or unexported fields
		},
	},

	"pg_catalog.pg_get_indexdef": {
		Builtin{
			Types: NamedArgTypes{
				{"index_oid", TypeInt},
			},
			ReturnType: TypeString,

			Info: "Not usable; supported only for ORM compatibility",
			// contains filtered or unexported fields
		},
	},

	"pg_catalog.pg_typeof": {

		Builtin{
			Types:      NamedArgTypes{{"val", TypeAny}},
			ReturnType: TypeString,

			Info: "Not usable; supported only for ORM compatibility",
			// contains filtered or unexported fields
		},
	},
	"pg_catalog.pg_get_userbyid": {
		Builtin{
			Types: NamedArgTypes{
				{"role_oid", TypeInt},
			},
			ReturnType: TypeString,

			Info: "Not usable; supported only for ORM compatibility",
			// contains filtered or unexported fields
		},
	},
	"pg_catalog.format_type": {
		Builtin{

			Types:      NamedArgTypes{{"type_oid", TypeInt}, {"typemod", TypeInt}},
			ReturnType: TypeString,

			Info: "format_type returns the SQL name of a data type that is " +
				"identified by its type OID and possibly a type modifier. " +
				"Currently, the type modifier is ignored.",
			// contains filtered or unexported fields
		},
	},
	"pg_catalog.col_description": {
		Builtin{
			Types:      NamedArgTypes{{"table_oid", TypeInt}, {"column_number", TypeInt}},
			ReturnType: TypeString,

			Info: "col_description returns the comment for a table column. " +
				"Currently, CockroachDB does not support adding comments to columns.",
			// 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:  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),
	},

	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.

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) (DBool, 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 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 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 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(Datum)

	// 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
}

AggregateFunc accumulates the result of a function of a Datum.

func NewIdentAggregate

func NewIdentAggregate() 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) Eval

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

Eval implements the TypedExpr interface.

func (*AnnotateTypeExpr) Format

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

Format implements the NodeFormatter interface.

func (AnnotateTypeExpr) ResolvedType

func (ta AnnotateTypeExpr) ResolvedType() Type

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 AnyType

type AnyType struct{}

AnyType is a typeList implementation that accepts any arguments.

func (AnyType) Length

func (a AnyType) Length() int

Length implements the typeList interface.

func (AnyType) String

func (AnyType) String() string

func (AnyType) Types

func (a AnyType) Types() []Type

Types implements the typeList interface.

type ArgTypes

type ArgTypes []Type

ArgTypes is a typeList implementation that accepts a specific number of argument types.

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 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              string
	IncrementalFrom []string
	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
	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 Type

	// 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() AggregateFunc
	WindowFunc    func() 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) ContextDependent

func (b Builtin) ContextDependent() bool

ContextDependent returns true if this builtin depends on data stored in the EvalContext.

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.

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 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 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    *StrVal
	Encoding    *StrVal
	Collate     *StrVal
	CType       *StrVal
}

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 (*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 *StrVal
}

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) 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    []Datum
}

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

func NewDArray

func NewDArray(paramTyp Type) *DArray

NewDArray returns a DArray containing elements of the specified type.

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(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

func (*DArray) Less

func (d *DArray) Less(i, j int) bool

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

func (d *DArray) Swap(i, j int)

func (*DArray) TypeCheck

func (d *DArray) TypeCheck(_ *SemaContext, desired 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) Compare

func (d *DBool) Compare(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, desired 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) Compare

func (d *DBytes) Compare(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