parser

package
v0.0.0-...-bf59245 Latest Latest
Warning

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

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

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

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

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

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

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

time.Time formats.

View Source
const UMINUS = 57677
View Source
const UNBOUNDED = 57644
View Source
const UNCOMMITTED = 57645
View Source
const UNION = 57646
View Source
const UNIQUE = 57647
View Source
const UNKNOWN = 57648
View Source
const UPDATE = 57649
View Source
const UPSERT = 57650
View Source
const USE = 57651
View Source
const USER = 57652
View Source
const USERS = 57653
View Source
const USING = 57654
View Source
const UUID = 57655
View Source
const VALID = 57656
View Source
const VALIDATE = 57657
View Source
const VALUE = 57658
View Source
const VALUES = 57659
View Source
const VARCHAR = 57660
View Source
const VARIADIC = 57661
View Source
const VARYING = 57663
View Source
const VIEW = 57662
View Source
const WHEN = 57664
View Source
const WHERE = 57665
View Source
const WINDOW = 57666
View Source
const WITH = 57667
View Source
const WITHIN = 57668
View Source
const WITHOUT = 57669
View Source
const WITH_LA = 57674
View Source
const WRITE = 57670
View Source
const YEAR = 57671
View Source
const ZONE = 57672

Variables

View Source
var (

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

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

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

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

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

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

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

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

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

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

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

	"concat_agg": {

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

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

	"count_rows": {
		{

			Types:         ArgTypes{},
			ReturnType:    fixedReturnType(TypeInt),
			AggregateFunc: newCountRowsAggregate,
			WindowFunc: func(params []Type, evalCtx *EvalContext) WindowFunc {
				return newAggregateWindow(newCountRowsAggregate(params, evalCtx))
			},
			Info: "Calculates the number of rows.",
			// contains filtered or unexported fields
		},
	},

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

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

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

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

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

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

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

View Source
var AllBuiltinNames []string

AllBuiltinNames is an array containing all the built-in function names, sorted in alphabetical order. This can be used for a deterministic walk through the Builtins map.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

BinOps contains the binary operations indexed by operation type.

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

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

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

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

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

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

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

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

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

			Info: "Uses the first argument as a separator between the concatenation of the " +
				"subsequent arguments. <br/><br/>For example `concat_ws('!','wow','great')` " +
				"returns `wow!great`.",
			// contains filtered or unexported fields
		},
	},

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

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

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

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

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

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

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

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

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

			Info: "Splits `input` on `delimiter` and return the value in the `return_index_pos`  " +
				"position (starting at 1). <br/><br/>For example, `split_part('123.456.789.0','.',3)`" +
				"returns `789`.",
			// contains filtered or unexported fields
		},
	},

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

			ReturnType: fixedReturnType(TypeString),

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

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

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

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

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

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

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

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

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

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

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

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

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

			Info: "Converts `val` to its hexadecimal representation.",
			// contains filtered or unexported fields
		},
		Builtin{
			Types:      ArgTypes{{"val", TypeBytes}},
			ReturnType: fixedReturnType(TypeString),

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

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

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

	"overlay": {
		Builtin{
			Types: ArgTypes{
				{"input", TypeString},
				{"overlay_val", TypeString},
				{"start_pos", TypeInt},
			},
			ReturnType: fixedReturnType(TypeString),

			Info: "Replaces characters in `input` with `overlay_val` starting at `start_pos` " +
				"(begins at 1). <br/><br/>For example, `overlay('doggie', 'CAT', 2)` returns " +
				"`dCATie`.",
			// contains filtered or unexported fields
		},
		Builtin{
			Types: ArgTypes{
				{"input", TypeString},
				{"overlay_val", TypeString},
				{"start_pos", TypeInt},
				{"end_pos", TypeInt},
			},
			ReturnType: fixedReturnType(TypeString),

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

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

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

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

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

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

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

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

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

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

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

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

			Info: "Replaces matches for the Regular Expression `regex` in `input` with the Regular " +
				"Expression `replace` using `flags`.<br/><br/>CockroachDB supports the following " +
				"flags:<br/><br/>&#8226; **c**: Case-sensitive matching<br/><br/>&#8226; **g**: " +
				"Global matching (match each substring instead of only the first).<br/><br/>&#8226; " +
				"**i**: Case-insensitive matching<br/><br/>&#8226; **m** or **n**: Newline-sensitive " +
				"`.` and negated brackets (`[^...]`) do not match newline characters (preventing " +
				"matching: matches from crossing newlines unless explicitly defined to); `^` and " +
				"`$` match the space before and after newline characters respectively (so characters " +
				"between newline characters are treated as if they're on a separate line).<br/>" +
				"<br/>&#8226; **p**: Partial newline-sensitive matching: `.` and negated brackets " +
				"(`[^...]`) do not match newline characters (preventing matches from crossing " +
				"newlines unless explicitly defined to), but `^` and `$` still only match the " +
				"beginning and end of `val`.<br/><br/>&#8226; **s**: Newline-insensitive " +
				"matching *(default)*.<br/><br/>&#8226; **w**: Inverse partial newline-sensitive " +
				"matching:`.` and negated brackets (`[^...]`) *do* match newline characters, but  `^` " +
				"and `$` match the space before and after newline characters respectively (so " +
				"characters between newline characters are treated as if they're on a separate line).",
			// contains filtered or unexported fields
		},
	},

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

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

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

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

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

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

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

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

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

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

			Info: "Returns a unique ID used by CockroachDB to generate unique row IDs if a " +
				"Primary Key isn't defined for the table. The value is a combination of the " +
				" insert timestamp and the ID of the node executing the statement, which " +
				" guarantees this combination is globally unique.",
			// contains filtered or unexported fields
		},
	},

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

			Info: "Extracts `element` from `input`. Compatible `elements` are: <br/>&#8226; " +
				"year<br/>&#8226; quarter<br/>&#8226; month<br/>&#8226; week<br/>&#8226; " +
				"dayofweek<br/>&#8226; dayofyear<br/>&#8226; hour<br/>&#8226; minute<br/>&#8226; " +
				"second<br/>&#8226; millisecond<br/>&#8226; microsecond<br/>&#8226; epoch",
			// contains filtered or unexported fields
		},
		Builtin{
			Types:      ArgTypes{{"element", TypeString}, {"input", TypeDate}},
			ReturnType: fixedReturnType(TypeInt),

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

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

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

	"abs": {
		floatBuiltin1(func(x float64) (Datum, error) {
			return NewDFloat(DFloat(math.Abs(x))), nil
		}, "Calculates the absolute value of `val`."),
		decimalBuiltin1(func(x *apd.Decimal) (Datum, error) {
			dd := &DDecimal{}
			dd.Abs(x)
			return dd, nil
		}, "Calculates the absolute value of `val`."),
		Builtin{
			Types:      ArgTypes{{"val", TypeInt}},
			ReturnType: fixedReturnType(TypeInt),

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	"isnan": {
		Builtin{

			Types:      ArgTypes{{"val", TypeFloat}},
			ReturnType: fixedReturnType(TypeBool),

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

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

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

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

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

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

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

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

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

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

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

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

			Info: "Keeps `decimal_accuracy` number of figures to the right of the zero position " +
				" in `input using half away from zero rounding. If `decimal_accuracy` " +
				"is not in the range -2^31...(2^31-1), the results are undefined.",
			// contains filtered or unexported fields
		},
	},

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

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

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

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

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

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

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

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

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

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

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

			Info: "Calculates the length of `input` on the provided `array_dimension`. However, " +
				"because CockroachDB doesn't yet support multi-dimensional arrays, the only supported" +
				" `array_dimension` is **1**.",
			// contains filtered or unexported fields
		},
	},

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

			Info: "Calculates the minimum value of `input` on the provided `array_dimension`. " +
				"However, because CockroachDB doesn't yet support multi-dimensional arrays, the only " +
				"supported `array_dimension` is **1**.",
			// contains filtered or unexported fields
		},
	},

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

			Info: "Calculates the maximum value of `input` on the provided `array_dimension`. " +
				"However, because CockroachDB doesn't yet support multi-dimensional arrays, the only " +
				"supported `array_dimension` is **1**.",
			// contains filtered or unexported fields
		},
	},

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

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

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

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

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

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

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

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

	"crdb_internal.cluster_id": {
		Builtin{
			Types:      ArgTypes{},
			ReturnType: fixedReturnType(TypeUUID),

			Info: "Returns the cluster ID.",
			// contains filtered or unexported fields
		},
	},

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

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

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

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

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

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

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

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

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

	"crdb_internal.no_constant_folding": {
		Builtin{
			Types:      ArgTypes{{"input", TypeAny}},
			ReturnType: identityReturnType(0),

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

Builtins contains the built-in functions indexed by name.

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

	LT: {
		CmpOp{
			LeftType:  TypeString,
			RightType: TypeString,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeCollatedString,
			RightType: TypeCollatedString,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeBytes,
			RightType: TypeBytes,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeBool,
			RightType: TypeBool,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeInt,
			RightType: TypeInt,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeFloat,
			RightType: TypeFloat,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDecimal,
			RightType: TypeDecimal,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeFloat,
			RightType: TypeInt,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeInt,
			RightType: TypeFloat,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDecimal,
			RightType: TypeInt,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeInt,
			RightType: TypeDecimal,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDecimal,
			RightType: TypeFloat,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeFloat,
			RightType: TypeDecimal,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDate,
			RightType: TypeDate,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestamp,
			RightType: TypeTimestamp,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestampTZ,
			RightType: TypeTimestampTZ,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestamp,
			RightType: TypeTimestampTZ,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestampTZ,
			RightType: TypeTimestamp,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDate,
			RightType: TypeTimestampTZ,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeDate,
			RightType: TypeTimestamp,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestampTZ,
			RightType: TypeDate,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeTimestamp,
			RightType: TypeDate,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeInterval,
			RightType: TypeInterval,
			// contains filtered or unexported fields
		},
		CmpOp{
			LeftType:  TypeUUID,
			RightType: TypeUUID,
			// 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:  TypeUUID,
			RightType: TypeUUID,
			// 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(TypeUUID),
		makeEvalTupleIn(TypeTuple),
		makeEvalTupleIn(TypeOid),
	},

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

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

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

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

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

CmpOps contains the comparison operations indexed by operation type.

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

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

OidToType maps Postgres object IDs to CockroachDB types.

View Source
var 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 EscapeSQLString

func EscapeSQLString(in string) string

EscapeSQLString returns an escaped SQL representation of the given string. This is suitable for safely producing a SQL string valid for input to the parser.

func ExprDebugString

func ExprDebugString(expr Expr) string

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

func FindEqualComparisonFunction

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

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

func FormatNode

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

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

func HasReturningClause

func HasReturningClause(clause ReturningClause) bool

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

func 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 LimitDecimalWidth

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

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

func NewInvalidTableNameError

func NewInvalidTableNameError(tn string) error

NewInvalidTableNameError initializes an error carrying the pg code CodeInvalidNameError.

func PGDisplayName

func PGDisplayName(typ Type) string

PGDisplayName returns the Postgres display name for a given type.

func PGIOBuiltinPrefix

func PGIOBuiltinPrefix(typ Type) string

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

func ReNormalizeName

func ReNormalizeName(name string) string

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

func Serialize

func Serialize(n NodeFormatter) string

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

func SimilarEscape

func SimilarEscape(pattern string) string

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

func StmtDebugString

func StmtDebugString(stmt Statement) string

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

func ValidateRestartCheckpoint

func ValidateRestartCheckpoint(savepoint string) error

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

func WalkExprConst

func WalkExprConst(v Visitor, expr Expr)

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

Types

type AggregateFunc

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

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

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

AggregateFunc accumulates the result of a function of a Datum.

func NewIdentAggregate

func NewIdentAggregate(*EvalContext) AggregateFunc

NewIdentAggregate returns an identAggregate (see comment on struct).

type AliasClause

type AliasClause struct {
	Alias Name
	Cols  NameList
}

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

func (AliasClause) Format

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

Format implements the NodeFormatter interface.

type AliasedTableExpr

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

AliasedTableExpr represents a table expression coupled with an optional alias.

func (*AliasedTableExpr) Format

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

Format implements the NodeFormatter interface.

func (*AliasedTableExpr) String

func (node *AliasedTableExpr) String() string

type AllColumnsSelector

type AllColumnsSelector struct {
	TableName
}

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

func (*AllColumnsSelector) Eval

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

Eval implements the TypedExpr interface.

func (*AllColumnsSelector) Format

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

Format implements the NodeFormatter interface.

func (*AllColumnsSelector) NormalizeVarName

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

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

func (*AllColumnsSelector) ResolvedType

func (*AllColumnsSelector) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*AllColumnsSelector) String

func (a *AllColumnsSelector) String() string

func (*AllColumnsSelector) TypeCheck

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

TypeCheck implements the Expr interface.

func (*AllColumnsSelector) Variable

func (a *AllColumnsSelector) Variable()

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

func (*AllColumnsSelector) Walk

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

Walk implements the Expr interface.

type AllTablesSelector

type AllTablesSelector struct {
	Database Name
}

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

func (*AllTablesSelector) Format

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

Format implements the NodeFormatter interface.

func (*AllTablesSelector) NormalizeTablePattern

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

NormalizeTablePattern implements the TablePattern interface.

func (*AllTablesSelector) QualifyWithDatabase

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

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

func (*AllTablesSelector) String

func (at *AllTablesSelector) String() string

type AlterTable

type AlterTable struct {
	IfExists bool
	Table    NormalizableTableName
	Cmds     AlterTableCmds
}

AlterTable represents an ALTER TABLE statement.

func (*AlterTable) Format

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

Format implements the NodeFormatter interface.

func (*AlterTable) StatementTag

func (*AlterTable) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*AlterTable) StatementType

func (*AlterTable) StatementType() StatementType

StatementType implements the Statement interface.

func (*AlterTable) String

func (n *AlterTable) String() string

type AlterTableAddColumn

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

AlterTableAddColumn represents an ADD COLUMN command.

func (*AlterTableAddColumn) Format

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

Format implements the NodeFormatter interface.

func (*AlterTableAddColumn) String

func (n *AlterTableAddColumn) String() string

type AlterTableAddConstraint

type AlterTableAddConstraint struct {
	ConstraintDef      ConstraintTableDef
	ValidationBehavior ValidationBehavior
}

AlterTableAddConstraint represents an ADD CONSTRAINT command.

func (*AlterTableAddConstraint) Format

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

Format implements the NodeFormatter interface.

func (*AlterTableAddConstraint) String

func (n *AlterTableAddConstraint) String() string

type AlterTableCmd

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

AlterTableCmd represents a table modification operation.

type AlterTableCmds

type AlterTableCmds []AlterTableCmd

AlterTableCmds represents a list of table alterations.

func (AlterTableCmds) Format

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

Format implements the NodeFormatter interface.

func (AlterTableCmds) String

func (n AlterTableCmds) String() string

type AlterTableDropColumn

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

AlterTableDropColumn represents a DROP COLUMN command.

func (*AlterTableDropColumn) Format

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

Format implements the NodeFormatter interface.

func (*AlterTableDropColumn) String

func (n *AlterTableDropColumn) String() string

type AlterTableDropConstraint

type AlterTableDropConstraint struct {
	IfExists     bool
	Constraint   Name
	DropBehavior DropBehavior
}

AlterTableDropConstraint represents a DROP CONSTRAINT command.

func (*AlterTableDropConstraint) Format

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

Format implements the NodeFormatter interface.

func (*AlterTableDropConstraint) String

func (n *AlterTableDropConstraint) String() string

type AlterTableDropNotNull

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

AlterTableDropNotNull represents an ALTER COLUMN DROP NOT NULL command.

func (*AlterTableDropNotNull) Format

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

Format implements the NodeFormatter interface.

func (*AlterTableDropNotNull) GetColumn

func (node *AlterTableDropNotNull) GetColumn() Name

GetColumn implements the ColumnMutationCmd interface.

func (*AlterTableDropNotNull) String

func (n *AlterTableDropNotNull) String() string

type AlterTableSetDefault

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

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

func (*AlterTableSetDefault) Format

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

Format implements the NodeFormatter interface.

func (*AlterTableSetDefault) GetColumn

func (node *AlterTableSetDefault) GetColumn() Name

GetColumn implements the ColumnMutationCmd interface.

func (*AlterTableSetDefault) String

func (n *AlterTableSetDefault) String() string

type AlterTableValidateConstraint

type AlterTableValidateConstraint struct {
	Constraint Name
}

AlterTableValidateConstraint represents a VALIDATE CONSTRAINT command.

func (*AlterTableValidateConstraint) Format

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

Format implements the NodeFormatter interface.

type AndExpr

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

AndExpr represents an AND expression.

func NewTypedAndExpr

func NewTypedAndExpr(left, right TypedExpr) *AndExpr

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

func (*AndExpr) Eval

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

Eval implements the TypedExpr interface.

func (*AndExpr) Format

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

Format implements the NodeFormatter interface.

func (AndExpr) ResolvedType

func (ta AndExpr) ResolvedType() Type

func (*AndExpr) String

func (node *AndExpr) String() string

func (*AndExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*AndExpr) TypedLeft

func (node *AndExpr) TypedLeft() TypedExpr

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

func (*AndExpr) TypedRight

func (node *AndExpr) TypedRight() TypedExpr

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

func (*AndExpr) Walk

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

Walk implements the Expr interface.

type AnnotateTypeExpr

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

AnnotateTypeExpr represents a ANNOTATE_TYPE(expr, type) expression.

func (*AnnotateTypeExpr) Format

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

Format implements the NodeFormatter interface.

func (*AnnotateTypeExpr) String

func (node *AnnotateTypeExpr) String() string

func (*AnnotateTypeExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*AnnotateTypeExpr) TypedInnerExpr

func (node *AnnotateTypeExpr) TypedInnerExpr() TypedExpr

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

func (*AnnotateTypeExpr) Walk

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

Walk implements the Expr interface.

type ArgTypes

type ArgTypes []struct {
	Name string
	Typ  Type
}

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

func (ArgTypes) Length

func (a ArgTypes) Length() int

Length implements the typeList interface.

func (ArgTypes) String

func (a ArgTypes) String() string

func (ArgTypes) Types

func (a ArgTypes) Types() []Type

Types implements the typeList interface.

type Array

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

Array represents an array constructor.

func (*Array) Eval

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

Eval implements the TypedExpr interface.

func (*Array) Format

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

Format implements the NodeFormatter interface.

func (Array) ResolvedType

func (ta Array) ResolvedType() Type

func (*Array) String

func (node *Array) String() string

func (*Array) TypeCheck

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

TypeCheck implements the Expr interface.

func (*Array) Walk

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

Walk implements the Expr interface.

type ArrayColType

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

ArrayColType represents an ARRAY column type.

func (*ArrayColType) Format

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

Format implements the NodeFormatter interface.

func (*ArrayColType) String

func (node *ArrayColType) String() string

type ArrayFlatten

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

ArrayFlatten represents a subquery array constructor.

func (*ArrayFlatten) Eval

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

Eval implements the TypedExpr interface.

func (*ArrayFlatten) Format

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

Format implements the NodeFormatter interface.

func (ArrayFlatten) ResolvedType

func (ta ArrayFlatten) ResolvedType() Type

func (*ArrayFlatten) String

func (node *ArrayFlatten) String() string

func (*ArrayFlatten) TypeCheck

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

TypeCheck implements the Expr interface.

func (*ArrayFlatten) Walk

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

Walk implements the Expr interface.

type ArraySubscript

type ArraySubscript struct {
	Begin Expr
	End   Expr
	Slice bool
}

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

func (*ArraySubscript) Format

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

Format implements the NodeFormatter interface.

type ArraySubscripts

type ArraySubscripts []*ArraySubscript

ArraySubscripts represents a sequence of one or more array subscripts.

func (ArraySubscripts) Format

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

Format implements the NodeFormatter interface.

type AsOfClause

type AsOfClause struct {
	Expr Expr
}

AsOfClause represents an as of time.

func (AsOfClause) Format

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

Format implements the NodeFormatter interface.

type Backup

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

Backup represents a BACKUP statement.

func (*Backup) Format

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

Format implements the NodeFormatter interface.

func (*Backup) StatementTag

func (*Backup) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Backup) StatementType

func (*Backup) StatementType() StatementType

StatementType implements the Statement interface.

func (*Backup) String

func (n *Backup) String() string

type BeginTransaction

type BeginTransaction struct {
	Modes TransactionModes
}

BeginTransaction represents a BEGIN statement

func (*BeginTransaction) Format

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

Format implements the NodeFormatter interface.

func (*BeginTransaction) StatementTag

func (*BeginTransaction) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*BeginTransaction) StatementType

func (*BeginTransaction) StatementType() StatementType

StatementType implements the Statement interface.

func (*BeginTransaction) String

func (n *BeginTransaction) String() string

type BinOp

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

BinOp is a binary operator.

type BinaryExpr

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

BinaryExpr represents a binary value expression.

func (*BinaryExpr) Eval

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

Eval implements the TypedExpr interface.

func (*BinaryExpr) Format

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

Format implements the NodeFormatter interface.

func (BinaryExpr) ResolvedType

func (ta BinaryExpr) ResolvedType() Type

func (*BinaryExpr) String

func (node *BinaryExpr) String() string

func (*BinaryExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*BinaryExpr) TypedLeft

func (node *BinaryExpr) TypedLeft() TypedExpr

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

func (*BinaryExpr) TypedRight

func (node *BinaryExpr) TypedRight() TypedExpr

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

func (*BinaryExpr) Walk

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

Walk implements the Expr interface.

type BinaryOperator

type BinaryOperator int

BinaryOperator represents a binary operator.

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

BinaryExpr.Operator

func (BinaryOperator) String

func (i BinaryOperator) String() string

type BoolColType

type BoolColType struct {
	Name string
}

BoolColType represents a BOOLEAN type.

func (*BoolColType) Format

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

Format implements the NodeFormatter interface.

func (*BoolColType) String

func (node *BoolColType) String() string

type Builtin

type Builtin struct {
	Types      typeList
	ReturnType returnTyper

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

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

Builtin is a built-in function.

func (Builtin) Category

func (b Builtin) Category() string

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

func (Builtin) Class

func (b Builtin) Class() FunctionClass

Class returns the FunctionClass of this builtin.

func (Builtin) DistSQLBlacklist

func (b Builtin) DistSQLBlacklist() bool

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

func (Builtin) FixedReturnType

func (b Builtin) FixedReturnType() Type

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

func (Builtin) Fn

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

Fn returns the Go function which implements the builtin.

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 CancelJob

type CancelJob struct {
	ID Expr
}

CancelJob represents a CANCEL JOB statement.

func (*CancelJob) Format

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

Format implements the NodeFormatter interface.

func (*CancelJob) StatementTag

func (*CancelJob) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CancelJob) StatementType

func (*CancelJob) StatementType() StatementType

StatementType implements the Statement interface.

func (*CancelJob) String

func (n *CancelJob) String() string

type CancelQuery

type CancelQuery struct {
	ID Expr
}

CancelQuery represents a CANCEL QUERY statement.

func (*CancelQuery) Format

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

Format implements the NodeFormatter interface.

func (*CancelQuery) StatementTag

func (*CancelQuery) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CancelQuery) StatementType

func (*CancelQuery) StatementType() StatementType

StatementType implements the Statement interface.

func (*CancelQuery) String

func (n *CancelQuery) String() string

type CaseExpr

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

CaseExpr represents a CASE expression.

func (*CaseExpr) CopyNode

func (expr *CaseExpr) CopyNode() *CaseExpr

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

func (*CaseExpr) Eval

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

Eval implements the TypedExpr interface.

func (*CaseExpr) Format

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

Format implements the NodeFormatter interface.

func (CaseExpr) ResolvedType

func (ta CaseExpr) ResolvedType() Type

func (*CaseExpr) String

func (node *CaseExpr) String() string

func (*CaseExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*CaseExpr) Walk

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

Walk implements the Expr interface.

type CastExpr

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

CastExpr represents a CAST(expr AS type) expression.

func (*CastExpr) Eval

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

Eval implements the TypedExpr interface.

func (*CastExpr) Format

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

Format implements the NodeFormatter interface.

func (CastExpr) ResolvedType

func (ta CastExpr) ResolvedType() Type

func (*CastExpr) String

func (node *CastExpr) String() string

func (*CastExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*CastExpr) Walk

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

Walk implements the Expr interface.

type CastTargetType

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

CastTargetType represents a type that is a valid cast target.

func ParseType

func ParseType(sql string) (CastTargetType, error)

ParseType parses a column type.

type CheckConstraintTableDef

type CheckConstraintTableDef struct {
	Name Name
	Expr Expr
}

CheckConstraintTableDef represents a check constraint within a CREATE TABLE statement.

func (*CheckConstraintTableDef) Format

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

Format implements the NodeFormatter interface.

type CmpOp

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

CmpOp is a comparison operator.

type CoalesceExpr

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

CoalesceExpr represents a COALESCE or IFNULL expression.

func (*CoalesceExpr) CopyNode

func (expr *CoalesceExpr) CopyNode() *CoalesceExpr

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

func (*CoalesceExpr) Eval

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

Eval implements the TypedExpr interface.

func (*CoalesceExpr) Format

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

Format implements the NodeFormatter interface.

func (CoalesceExpr) ResolvedType

func (ta CoalesceExpr) ResolvedType() Type

func (*CoalesceExpr) String

func (node *CoalesceExpr) String() string

func (*CoalesceExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*CoalesceExpr) TypedExprAt

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

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

func (*CoalesceExpr) Walk

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

Walk implements the Expr interface.

type CollateExpr

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

CollateExpr represents an (expr COLLATE locale) expression.

func (*CollateExpr) Eval

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

Eval implements the TypedExpr interface.

func (*CollateExpr) Format

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

Format implements the NodeFormatter interface.

func (CollateExpr) ResolvedType

func (ta CollateExpr) ResolvedType() Type

func (*CollateExpr) String

func (node *CollateExpr) String() string

func (*CollateExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*CollateExpr) Walk

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

Walk implements the Expr interface.

type CollatedStringColType

type CollatedStringColType struct {
	Name   string
	N      int
	Locale string
}

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

func (*CollatedStringColType) Format

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

Format implements the NodeFormatter interface.

func (*CollatedStringColType) String

func (node *CollatedStringColType) String() string

type CollationEnvironment

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

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

type ColumnCheckConstraint

type ColumnCheckConstraint struct {
	Expr Expr
}

ColumnCheckConstraint represents either a check on a column.

type ColumnCollation

type ColumnCollation string

ColumnCollation represents a COLLATE clause for a column.

type ColumnDefault

type ColumnDefault struct {
	Expr Expr
}

ColumnDefault represents a DEFAULT clause for a column.

type ColumnFKConstraint

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

ColumnFKConstraint represents a FK-constaint on a column.

type ColumnFamilyConstraint

type ColumnFamilyConstraint struct {
	Family      Name
	Create      bool
	IfNotExists bool
}

ColumnFamilyConstraint represents FAMILY on a column.

type ColumnID

type ColumnID uint32

ColumnID is a custom type for ColumnDescriptor IDs.

type ColumnItem

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

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

func (*ColumnItem) Column

func (c *ColumnItem) Column() string

Column retrieves the unqualified column name.

func (*ColumnItem) Eval

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

Eval implements the TypedExpr interface.

func (*ColumnItem) Format

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

Format implements the NodeFormatter interface.

func (*ColumnItem) NormalizeVarName

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

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

func (*ColumnItem) ResolvedType

func (c *ColumnItem) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*ColumnItem) String

func (c *ColumnItem) String() string

func (*ColumnItem) TypeCheck

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

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

func (*ColumnItem) Variable

func (c *ColumnItem) Variable()

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

func (*ColumnItem) Walk

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

Walk implements the Expr interface.

type ColumnMutationCmd

type ColumnMutationCmd interface {
	AlterTableCmd
	GetColumn() Name
}

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

type ColumnQualification

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

ColumnQualification represents a constraint on a column.

type ColumnTableDef

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

ColumnTableDef represents a column definition within a CREATE TABLE statement.

func (*ColumnTableDef) Format

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

Format implements the NodeFormatter interface.

func (*ColumnTableDef) HasColumnFamily

func (node *ColumnTableDef) HasColumnFamily() bool

HasColumnFamily returns if the ColumnTableDef has a column family.

func (*ColumnTableDef) HasDefaultExpr

func (node *ColumnTableDef) HasDefaultExpr() bool

HasDefaultExpr returns if the ColumnTableDef has a default expression.

func (*ColumnTableDef) HasFKConstraint

func (node *ColumnTableDef) HasFKConstraint() bool

HasFKConstraint returns if the ColumnTableDef has a foreign key constraint.

type ColumnTableDefCheckExpr

type ColumnTableDefCheckExpr struct {
	Expr           Expr
	ConstraintName Name
}

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

type ColumnType

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

ColumnType represents a type in a column definition.

func DatumTypeToColumnType

func DatumTypeToColumnType(t Type) (ColumnType, error)

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

type CommitTransaction

type CommitTransaction struct{}

CommitTransaction represents a COMMIT statement.

func (*CommitTransaction) Format

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

Format implements the NodeFormatter interface.

func (*CommitTransaction) StatementTag

func (*CommitTransaction) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CommitTransaction) StatementType

func (*CommitTransaction) StatementType() StatementType

StatementType implements the Statement interface.

func (*CommitTransaction) String

func (n *CommitTransaction) String() string

type ComparisonExpr

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

ComparisonExpr represents a two-value comparison expression.

func NewTypedComparisonExpr

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

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

func (*ComparisonExpr) Eval

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

Eval implements the TypedExpr interface.

func (*ComparisonExpr) Format

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

Format implements the NodeFormatter interface.

func (*ComparisonExpr) IsMixedTypeComparison

func (node *ComparisonExpr) IsMixedTypeComparison() bool

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

func (ComparisonExpr) ResolvedType

func (ta ComparisonExpr) ResolvedType() Type

func (*ComparisonExpr) String

func (node *ComparisonExpr) String() string

func (*ComparisonExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*ComparisonExpr) TypedLeft

func (node *ComparisonExpr) TypedLeft() TypedExpr

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

func (*ComparisonExpr) TypedRight

func (node *ComparisonExpr) TypedRight() TypedExpr

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

func (*ComparisonExpr) Walk

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

Walk implements the Expr interface.

type ComparisonOperator

type ComparisonOperator int

ComparisonOperator represents a binary operator.

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

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

ComparisonExpr.Operator

func (ComparisonOperator) String

func (i ComparisonOperator) String() string

type CompositeDatum

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

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

type Constant

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

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

type ConstraintTableDef

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

ConstraintTableDef represents a constraint definition within a CREATE TABLE statement.

type ContainsWindowVisitor

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

ContainsWindowVisitor checks if walked expressions contain window functions.

func (*ContainsWindowVisitor) ContainsWindowFunc

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

ContainsWindowFunc determines if an Expr contains a window function.

func (*ContainsWindowVisitor) VisitPost

func (*ContainsWindowVisitor) VisitPost(expr Expr) Expr

VisitPost satisfies the Visitor interface.

func (*ContainsWindowVisitor) VisitPre

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

VisitPre satisfies the Visitor interface.

type CopyFrom

type CopyFrom struct {
	Table   NormalizableTableName
	Columns UnresolvedNames
	Stdin   bool
}

CopyFrom represents a COPY FROM statement.

func (*CopyFrom) Format

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

Format implements the NodeFormatter interface.

func (*CopyFrom) StatementTag

func (*CopyFrom) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CopyFrom) StatementType

func (*CopyFrom) StatementType() StatementType

StatementType implements the Statement interface.

func (*CopyFrom) String

func (n *CopyFrom) String() string

type CreateDatabase

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

CreateDatabase represents a CREATE DATABASE statement.

func (*CreateDatabase) Format

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

Format implements the NodeFormatter interface.

func (*CreateDatabase) StatementTag

func (*CreateDatabase) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CreateDatabase) StatementType

func (*CreateDatabase) StatementType() StatementType

StatementType implements the Statement interface.

func (*CreateDatabase) String

func (n *CreateDatabase) String() string

type CreateIndex

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

CreateIndex represents a CREATE INDEX statement.

func (*CreateIndex) Format

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

Format implements the NodeFormatter interface.

func (*CreateIndex) StatementTag

func (*CreateIndex) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CreateIndex) StatementType

func (*CreateIndex) StatementType() StatementType

StatementType implements the Statement interface.

func (*CreateIndex) String

func (n *CreateIndex) String() string

type CreateTable

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

CreateTable represents a CREATE TABLE statement.

func (*CreateTable) As

func (node *CreateTable) As() bool

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

func (*CreateTable) Format

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

Format implements the NodeFormatter interface.

func (*CreateTable) StatementTag

func (n *CreateTable) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CreateTable) StatementType

func (*CreateTable) StatementType() StatementType

StatementType implements the Statement interface.

func (*CreateTable) String

func (n *CreateTable) String() string

type CreateUser

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

CreateUser represents a CREATE USER statement.

func (*CreateUser) Format

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

Format implements the NodeFormatter interface.

func (*CreateUser) HasPassword

func (node *CreateUser) HasPassword() bool

HasPassword returns if the CreateUser has a password.

func (*CreateUser) StatementTag

func (*CreateUser) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CreateUser) StatementType

func (*CreateUser) StatementType() StatementType

StatementType implements the Statement interface.

func (*CreateUser) String

func (n *CreateUser) String() string

type CreateView

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

CreateView represents a CREATE VIEW statement.

func (*CreateView) Format

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

Format implements the NodeFormatter interface.

func (*CreateView) StatementTag

func (*CreateView) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*CreateView) StatementType

func (*CreateView) StatementType() StatementType

StatementType implements the Statement interface.

func (*CreateView) String

func (n *CreateView) String() string

type DArray

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

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

func AsDArray

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

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

func MustBeDArray

func MustBeDArray(e Expr) *DArray

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

func NewDArray

func NewDArray(paramTyp Type) *DArray

NewDArray returns a DArray containing elements of the specified type.

func (*DArray) AmbiguousFormat

func (*DArray) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DArray) Append

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

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

func (*DArray) Compare

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

Compare implements the Datum interface.

func (*DArray) Eval

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

Eval implements the TypedExpr interface.

func (*DArray) Format

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

Format implements the NodeFormatter interface.

func (*DArray) IsMax

func (d *DArray) IsMax() bool

IsMax implements the Datum interface.

func (*DArray) IsMin

func (d *DArray) IsMin() bool

IsMin implements the Datum interface.

func (*DArray) Len

func (d *DArray) Len() int

Len returns the length of the Datum array.

func (*DArray) Next

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

Next implements the Datum interface.

func (*DArray) Prev

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

Prev implements the Datum interface.

func (*DArray) ResolvedType

func (d *DArray) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DArray) Size

func (d *DArray) Size() uintptr

Size implements the Datum interface.

func (*DArray) String

func (node *DArray) String() string

func (*DArray) TypeCheck

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

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

func (*DArray) Walk

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

Walk implements the Expr interface.

type DBool

type DBool bool

DBool is the boolean Datum.

func GetBool

func GetBool(d Datum) (DBool, error)

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

func MakeDBool

func MakeDBool(d DBool) *DBool

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

func ParseDBool

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

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

func (*DBool) AmbiguousFormat

func (*DBool) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DBool) Compare

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

Compare implements the Datum interface.

func (*DBool) Eval

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

Eval implements the TypedExpr interface.

func (*DBool) Format

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

Format implements the NodeFormatter interface.

func (*DBool) IsMax

func (d *DBool) IsMax() bool

IsMax implements the Datum interface.

func (*DBool) IsMin

func (d *DBool) IsMin() bool

IsMin implements the Datum interface.

func (*DBool) Next

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

Next implements the Datum interface.

func (*DBool) Prev

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

Prev implements the Datum interface.

func (*DBool) ResolvedType

func (*DBool) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DBool) Size

func (d *DBool) Size() uintptr

Size implements the Datum interface.

func (*DBool) String

func (node *DBool) String() string

func (*DBool) TypeCheck

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

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

func (*DBool) Walk

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

Walk implements the Expr interface.

type DBytes

type DBytes string

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

func NewDBytes

func NewDBytes(d DBytes) *DBytes

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

func (*DBytes) AmbiguousFormat

func (*DBytes) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DBytes) Compare

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

Compare implements the Datum interface.

func (*DBytes) Eval

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

Eval implements the TypedExpr interface.

func (*DBytes) Format

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

Format implements the NodeFormatter interface.

func (*DBytes) IsMax

func (*DBytes) IsMax() bool

IsMax implements the Datum interface.

func (*DBytes) IsMin

func (d *DBytes) IsMin() bool

IsMin implements the Datum interface.

func (*DBytes) Next

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

Next implements the Datum interface.

func (*DBytes) Prev

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

Prev implements the Datum interface.

func (*DBytes) ResolvedType

func (*DBytes) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DBytes) Size

func (d *DBytes) Size() uintptr

Size implements the Datum interface.

func (*DBytes) String

func (node *DBytes) String() string

func (*DBytes) TypeCheck

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

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

func (*DBytes) Walk

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

Walk implements the Expr interface.

type DCollatedString

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

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

func NewDCollatedString

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

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

func (*DCollatedString) AmbiguousFormat

func (*DCollatedString) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DCollatedString) Compare

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

Compare implements the Datum interface.

func (*DCollatedString) Eval

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

Eval implements the TypedExpr interface.

func (*DCollatedString) Format

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

Format implements the NodeFormatter interface.

func (*DCollatedString) IsComposite

func (d *DCollatedString) IsComposite() bool

IsComposite implements the CompositeDatum interface.

func (*DCollatedString) IsMax

func (*DCollatedString) IsMax() bool

IsMax implements the Datum interface.

func (*DCollatedString) IsMin

func (d *DCollatedString) IsMin() bool

IsMin implements the Datum interface.

func (*DCollatedString) Next

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

Next implements the Datum interface.

func (*DCollatedString) Prev

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

Prev implements the Datum interface.

func (*DCollatedString) ResolvedType

func (d *DCollatedString) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DCollatedString) Size

func (d *DCollatedString) Size() uintptr

Size implements the Datum interface.

func (*DCollatedString) String

func (node *DCollatedString) String() string

func (*DCollatedString) TypeCheck

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

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

func (*DCollatedString) Walk

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

Walk implements the Expr interface.

type DDate

type DDate int64

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

func NewDDate

func NewDDate(d DDate) *DDate

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

func NewDDateFromTime

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

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

func ParseDDate

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

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

func (*DDate) AmbiguousFormat

func (*DDate) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DDate) Compare

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

Compare implements the Datum interface.

func (*DDate) Eval

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

Eval implements the TypedExpr interface.

func (*DDate) Format

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

Format implements the NodeFormatter interface.

func (*DDate) IsMax

func (d *DDate) IsMax() bool

IsMax implements the Datum interface.

func (*DDate) IsMin

func (d *DDate) IsMin() bool

IsMin implements the Datum interface.

func (*DDate) Next

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

Next implements the Datum interface.

func (*DDate) Prev

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

Prev implements the Datum interface.

func (*DDate) ResolvedType

func (*DDate) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DDate) Size

func (d *DDate) Size() uintptr

Size implements the Datum interface.

func (*DDate) String

func (node *DDate) String() string

func (*DDate) TypeCheck

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

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

func (*DDate) Walk

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

Walk implements the Expr interface.

type DDecimal

type DDecimal struct {
	apd.Decimal
}

DDecimal is the decimal Datum.

var DecimalOne DDecimal

DecimalOne represents the constant 1 as DECIMAL.

func ParseDDecimal

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

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

func TimestampToDecimal

func TimestampToDecimal(ts hlc.Timestamp) *DDecimal

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

func (*DDecimal) AmbiguousFormat

func (*DDecimal) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DDecimal) Compare

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

Compare implements the Datum interface.

func (*DDecimal) Eval

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

Eval implements the TypedExpr interface.

func (*DDecimal) Format

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

Format implements the NodeFormatter interface.

func (*DDecimal) IsComposite

func (d *DDecimal) IsComposite() bool

IsComposite implements the CompositeDatum interface.

func (*DDecimal) IsMax

func (*DDecimal) IsMax() bool

IsMax implements the Datum interface.

func (*DDecimal) IsMin

func (*DDecimal) IsMin() bool

IsMin implements the Datum interface.

func (*DDecimal) Next

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

Next implements the Datum interface.

func (*DDecimal) Prev

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

Prev implements the Datum interface.

func (*DDecimal) ResolvedType

func (*DDecimal) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DDecimal) SetString

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

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

func (*DDecimal) Size

func (d *DDecimal) Size() uintptr

Size implements the Datum interface.

func (*DDecimal) String

func (node *DDecimal) String() string

func (*DDecimal) TypeCheck

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

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

func (*DDecimal) Walk

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

Walk implements the Expr interface.

type DFloat

type DFloat float64

DFloat is the float Datum.

func NewDFloat

func NewDFloat(d DFloat) *DFloat

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

func ParseDFloat

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

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

func (*DFloat) AmbiguousFormat

func (*DFloat) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DFloat) Compare

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

Compare implements the Datum interface.

func (*DFloat) Eval

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

Eval implements the TypedExpr interface.

func (*DFloat) Format

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

Format implements the NodeFormatter interface.

func (*DFloat) IsComposite

func (d *DFloat) IsComposite() bool

IsComposite implements the CompositeDatum interface.

func (*DFloat) IsMax

func (d *DFloat) IsMax() bool

IsMax implements the Datum interface.

func (*DFloat) IsMin

func (d *DFloat) IsMin() bool

IsMin implements the Datum interface.

func (*DFloat) Next

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

Next implements the Datum interface.

func (*DFloat) Prev

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

Prev implements the Datum interface.

func (*DFloat) ResolvedType

func (*DFloat) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DFloat) Size

func (d *DFloat) Size() uintptr

Size implements the Datum interface.

func (*DFloat) String

func (node *DFloat) String() string

func (*DFloat) TypeCheck

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

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

func (*DFloat) Walk

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

Walk implements the Expr interface.

type DInt

type DInt int64

DInt is the int Datum.

func AsDInt

func AsDInt(e Expr) (DInt, bool)

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

func GenerateUniqueInt

func GenerateUniqueInt(nodeID roachpb.NodeID) DInt

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

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

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

func MustBeDInt

func MustBeDInt(e Expr) DInt

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

func NewDInt

func NewDInt(d DInt) *DInt

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

func ParseDInt

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

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

func (*DInt) AmbiguousFormat

func (*DInt) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DInt) Compare

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

Compare implements the Datum interface.

func (*DInt) Eval

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

Eval implements the TypedExpr interface.

func (*DInt) Format

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

Format implements the NodeFormatter interface.

func (*DInt) IsMax

func (d *DInt) IsMax() bool

IsMax implements the Datum interface.

func (*DInt) IsMin

func (d *DInt) IsMin() bool

IsMin implements the Datum interface.

func (*DInt) Next

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

Next implements the Datum interface.

func (*DInt) Prev

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

Prev implements the Datum interface.

func (*DInt) ResolvedType

func (*DInt) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DInt) Size

func (d *DInt) Size() uintptr

Size implements the Datum interface.

func (*DInt) String

func (node *DInt) String() string

func (*DInt) TypeCheck

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

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

func (*DInt) Walk

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

Walk implements the Expr interface.

type DInterval

type DInterval struct {
	duration.Duration
}

DInterval is the interval Datum.

func ParseDInterval

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

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

func ParseDIntervalWithField

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

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

func (*DInterval) AmbiguousFormat

func (*DInterval) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DInterval) Compare

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

Compare implements the Datum interface.

func (*DInterval) Eval

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

Eval implements the TypedExpr interface.

func (*DInterval) Format

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

Format implements the NodeFormatter interface.

func (*DInterval) IsMax

func (d *DInterval) IsMax() bool

IsMax implements the Datum interface.

func (*DInterval) IsMin

func (d *DInterval) IsMin() bool

IsMin implements the Datum interface.

func (*DInterval) Next

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

Next implements the Datum interface.

func (*DInterval) Prev

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

Prev implements the Datum interface.

func (*DInterval) ResolvedType

func (*DInterval) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DInterval) Size

func (d *DInterval) Size() uintptr

Size implements the Datum interface.

func (*DInterval) String

func (node *DInterval) String() string

func (*DInterval) TypeCheck

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

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

func (*DInterval) ValueAsString

func (d *DInterval) ValueAsString() string

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

func (*DInterval) Walk

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

Walk implements the Expr interface.

type DOid

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

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

func MakeDOid

func MakeDOid(d DInt) DOid

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

func NewDOid

func NewDOid(d DInt) *DOid

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

func (*DOid) AmbiguousFormat

func (*DOid) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DOid) AsRegProc

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

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

func (*DOid) Compare

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

Compare implements the Datum interface.

func (*DOid) Eval

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

Eval implements the TypedExpr interface.

func (*DOid) Format

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

Format implements the Datum interface.

func (*DOid) IsMax

func (d *DOid) IsMax() bool

IsMax implements the Datum interface.

func (*DOid) IsMin

func (d *DOid) IsMin() bool

IsMin implements the Datum interface.

func (*DOid) Next

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

Next implements the Datum interface.

func (*DOid) Prev

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

Prev implements the Datum interface.

func (*DOid) ResolvedType

func (d *DOid) ResolvedType() Type

ResolvedType implements the Datum interface.

func (*DOid) Size

func (d *DOid) Size() uintptr

Size implements the Datum interface.

func (*DOid) String

func (node *DOid) String() string

func (*DOid) TypeCheck

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

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

func (*DOid) Walk

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

Walk implements the Expr interface.

type DOidWrapper

type DOidWrapper struct {
	Wrapped Datum
	Oid     oid.Oid
}

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

Instead, DOidWrapper allows a standard Datum to be wrapped with a new Oid. This approach provides two major advantages:

  • performance of the existing Datum types are not affected because they do not need to have custom oid.Oids added to their structure.
  • the introduction of new Datum aliases is straightforward and does not require additions to typing rules or type-dependent evaluation behavior.

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

func (*DOidWrapper) AmbiguousFormat

func (d *DOidWrapper) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DOidWrapper) Compare

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

Compare implements the Datum interface.

func (*DOidWrapper) Eval

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

Eval implements the TypedExpr interface.

func (*DOidWrapper) Format

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

Format implements the NodeFormatter interface.

func (*DOidWrapper) IsMax

func (d *DOidWrapper) IsMax() bool

IsMax implements the Datum interface.

func (*DOidWrapper) IsMin

func (d *DOidWrapper) IsMin() bool

IsMin implements the Datum interface.

func (*DOidWrapper) Next

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

Next implements the Datum interface.

func (*DOidWrapper) Prev

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

Prev implements the Datum interface.

func (*DOidWrapper) ResolvedType

func (d *DOidWrapper) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DOidWrapper) Size

func (d *DOidWrapper) Size() uintptr

Size implements the Datum interface.

func (*DOidWrapper) String

func (node *DOidWrapper) String() string

func (*DOidWrapper) TypeCheck

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

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

func (*DOidWrapper) Walk

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

Walk implements the Expr interface.

type DString

type DString string

DString is the string Datum.

func AsDString

func AsDString(e Expr) (DString, bool)

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

func MustBeDString

func MustBeDString(e Expr) DString

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

func NewDString

func NewDString(d string) *DString

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

func (*DString) AmbiguousFormat

func (*DString) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DString) Compare

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

Compare implements the Datum interface.

func (*DString) Eval

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

Eval implements the TypedExpr interface.

func (*DString) Format

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

Format implements the NodeFormatter interface.

func (*DString) IsMax

func (*DString) IsMax() bool

IsMax implements the Datum interface.

func (*DString) IsMin

func (d *DString) IsMin() bool

IsMin implements the Datum interface.

func (*DString) Next

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

Next implements the Datum interface.

func (*DString) Prev

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

Prev implements the Datum interface.

func (*DString) ResolvedType

func (*DString) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DString) Size

func (d *DString) Size() uintptr

Size implements the Datum interface.

func (*DString) String

func (node *DString) String() string

func (*DString) TypeCheck

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

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

func (*DString) Walk

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

Walk implements the Expr interface.

type DTable

type DTable struct {
	ValueGenerator
}

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

func EmptyDTable

func EmptyDTable() *DTable

EmptyDTable returns a new, empty DTable.

func (*DTable) AmbiguousFormat

func (*DTable) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DTable) Compare

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

Compare implements the Datum interface.

func (*DTable) Eval

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

Eval implements the TypedExpr interface.

func (*DTable) Format

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

Format implements the NodeFormatter interface.

func (*DTable) IsMax

func (*DTable) IsMax() bool

IsMax implements the Datum interface.

func (*DTable) IsMin

func (*DTable) IsMin() bool

IsMin implements the Datum interface.

func (*DTable) Next

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

Next implements the Datum interface.

func (*DTable) Prev

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

Prev implements the Datum interface.

func (*DTable) ResolvedType

func (t *DTable) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DTable) Size

func (*DTable) Size() uintptr

Size implements the Datum interface.

func (*DTable) String

func (node *DTable) String() string

func (*DTable) TypeCheck

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

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

func (*DTable) Walk

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

Walk implements the Expr interface.

type DTimestamp

type DTimestamp struct {
	time.Time
}

DTimestamp is the timestamp Datum.

func MakeDTimestamp

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

MakeDTimestamp creates a DTimestamp with specified precision.

func ParseDTimestamp

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

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

func (*DTimestamp) AmbiguousFormat

func (*DTimestamp) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DTimestamp) Compare

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

Compare implements the Datum interface.

func (*DTimestamp) Eval

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

Eval implements the TypedExpr interface.

func (*DTimestamp) Format

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

Format implements the NodeFormatter interface.

func (*DTimestamp) IsMax

func (d *DTimestamp) IsMax() bool

IsMax implements the Datum interface.

func (*DTimestamp) IsMin

func (d *DTimestamp) IsMin() bool

IsMin implements the Datum interface.

func (*DTimestamp) Next

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

Next implements the Datum interface.

func (*DTimestamp) Prev

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

Prev implements the Datum interface.

func (*DTimestamp) ResolvedType

func (*DTimestamp) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DTimestamp) Size

func (d *DTimestamp) Size() uintptr

Size implements the Datum interface.

func (*DTimestamp) String

func (node *DTimestamp) String() string

func (*DTimestamp) TypeCheck

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

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

func (*DTimestamp) Walk

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

Walk implements the Expr interface.

type DTimestampTZ

type DTimestampTZ struct {
	time.Time
}

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

func MakeDTimestampTZ

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

MakeDTimestampTZ creates a DTimestampTZ with specified precision.

func MakeDTimestampTZFromDate

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

MakeDTimestampTZFromDate creates a DTimestampTZ from a DDate.

func ParseDTimestampTZ

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

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

func (*DTimestampTZ) AmbiguousFormat

func (*DTimestampTZ) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DTimestampTZ) Compare

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

Compare implements the Datum interface.

func (*DTimestampTZ) Eval

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

Eval implements the TypedExpr interface.

func (*DTimestampTZ) Format

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

Format implements the NodeFormatter interface.

func (*DTimestampTZ) IsMax

func (d *DTimestampTZ) IsMax() bool

IsMax implements the Datum interface.

func (*DTimestampTZ) IsMin

func (d *DTimestampTZ) IsMin() bool

IsMin implements the Datum interface.

func (*DTimestampTZ) Next

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

Next implements the Datum interface.

func (*DTimestampTZ) Prev

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

Prev implements the Datum interface.

func (*DTimestampTZ) ResolvedType

func (*DTimestampTZ) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DTimestampTZ) Size

func (d *DTimestampTZ) Size() uintptr

Size implements the Datum interface.

func (*DTimestampTZ) String

func (node *DTimestampTZ) String() string

func (*DTimestampTZ) TypeCheck

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

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

func (*DTimestampTZ) Walk

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

Walk implements the Expr interface.

type DTuple

type DTuple struct {
	D Datums

	Sorted bool
}

DTuple is the tuple Datum.

func NewDTuple

func NewDTuple(d ...Datum) *DTuple

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

func NewDTupleWithCap

func NewDTupleWithCap(c int) *DTuple

NewDTupleWithCap creates a *DTuple with the provided capacity.

func NewDTupleWithLen

func NewDTupleWithLen(l int) *DTuple

NewDTupleWithLen creates a *DTuple with the provided length.

func (*DTuple) AmbiguousFormat

func (*DTuple) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DTuple) AssertSorted

func (d *DTuple) AssertSorted()

AssertSorted asserts that the DTuple is sorted.

func (*DTuple) Compare

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

Compare implements the Datum interface.

func (*DTuple) Eval

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

Eval implements the TypedExpr interface.

func (*DTuple) Format

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

Format implements the NodeFormatter interface.

func (*DTuple) IsMax

func (d *DTuple) IsMax() bool

IsMax implements the Datum interface.

func (*DTuple) IsMin

func (d *DTuple) IsMin() bool

IsMin implements the Datum interface.

func (*DTuple) Next

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

Next implements the Datum interface.

func (*DTuple) Normalize

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

Normalize sorts and uniques the datum tuple.

func (*DTuple) Prev

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

Prev implements the Datum interface.

func (*DTuple) ResolvedType

func (d *DTuple) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DTuple) SearchSorted

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

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

func (*DTuple) SetSorted

func (d *DTuple) SetSorted() *DTuple

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

func (*DTuple) Size

func (d *DTuple) Size() uintptr

Size implements the Datum interface.

func (*DTuple) SortedDifference

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

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

func (*DTuple) String

func (node *DTuple) String() string

func (*DTuple) TypeCheck

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

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

func (*DTuple) Walk

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

Walk implements the Expr interface.

type DUuid

type DUuid struct {
	uuid.UUID
}

DUuid is the UUID Datum.

func NewDUuid

func NewDUuid(d DUuid) *DUuid

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

func ParseDUuidFromBytes

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

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

func ParseDUuidFromString

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

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

func (*DUuid) AmbiguousFormat

func (*DUuid) AmbiguousFormat() bool

AmbiguousFormat implements the Datum interface.

func (*DUuid) Compare

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

Compare implements the Datum interface.

func (*DUuid) Eval

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

Eval implements the TypedExpr interface.

func (*DUuid) Format

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

Format implements the NodeFormatter interface.

func (*DUuid) IsMax

func (d *DUuid) IsMax() bool

IsMax implements the Datum interface.

func (*DUuid) IsMin

func (d *DUuid) IsMin() bool

IsMin implements the Datum interface.

func (*DUuid) Next

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

Next implements the Datum interface.

func (*DUuid) Prev

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

Prev implements the Datum interface.

func (*DUuid) ResolvedType

func (*DUuid) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*DUuid) Size

func (d *DUuid) Size() uintptr

Size implements the Datum interface.

func (*DUuid) String

func (node *DUuid) String() string

func (*DUuid) TypeCheck

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

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

func (*DUuid) Walk

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

Walk implements the Expr interface.

type DateColType

type DateColType struct {
}

DateColType represents a DATE type.

func (*DateColType) Format

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

Format implements the NodeFormatter interface.

func (*DateColType) String

func (node *DateColType) String() string

type Datum

type Datum interface {
	TypedExpr

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

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

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

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

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

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

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

Datum represents a SQL value.

func NewDIntVectorFromDArray

func NewDIntVectorFromDArray(d *DArray) Datum

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

func NewDName

func NewDName(d string) Datum

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

func NewDNameFromDString

func NewDNameFromDString(d *DString) Datum

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

func ParseStringAs

func ParseStringAs(t Type, s string, location *time.Location) (Datum, error)

ParseStringAs parses s as type t.

func UnwrapDatum

func UnwrapDatum(d Datum) Datum

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

type Datums

type Datums []Datum

Datums is a slice of Datum values.

func (Datums) Format

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

Format implements the NodeFormatter interface.

func (Datums) Len

func (d Datums) Len() int

Len returns the number of Datum values.

func (Datums) Reverse

func (d Datums) Reverse()

Reverse reverses the order of the Datum values.

func (*Datums) String

func (node *Datums) String() string

type Deallocate

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

Deallocate represents a DEALLOCATE statement.

func (*Deallocate) Format

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

Format implements the NodeFormatter interface.

func (*Deallocate) StatementTag

func (n *Deallocate) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Deallocate) StatementType

func (*Deallocate) StatementType() StatementType

StatementType implements the Statement interface.

func (*Deallocate) String

func (n *Deallocate) String() string

type DecimalColType

type DecimalColType struct {
	Name  string
	Prec  int
	Scale int
}

DecimalColType represents a DECIMAL or NUMERIC type.

func (*DecimalColType) Format

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

Format implements the NodeFormatter interface.

func (*DecimalColType) String

func (node *DecimalColType) String() string

type DefaultVal

type DefaultVal struct{}

DefaultVal represents the DEFAULT expression.

func (DefaultVal) Eval

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

Eval implements the TypedExpr interface.

func (DefaultVal) Format

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

Format implements the NodeFormatter interface.

func (DefaultVal) ResolvedType

func (DefaultVal) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (DefaultVal) String

func (node DefaultVal) String() string

func (DefaultVal) TypeCheck

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

TypeCheck implements the Expr interface.

func (DefaultVal) Walk

func (expr DefaultVal) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type Delete

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

Delete represents a DELETE statement.

func (*Delete) CopyNode

func (stmt *Delete) CopyNode() *Delete

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

func (*Delete) Format

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

Format implements the NodeFormatter interface.

func (*Delete) StatementTag

func (*Delete) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Delete) StatementType

func (n *Delete) StatementType() StatementType

StatementType implements the Statement interface.

func (*Delete) String

func (n *Delete) String() string

func (*Delete) WalkStmt

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

WalkStmt is part of the WalkableStmt interface.

type Direction

type Direction int

Direction for ordering results.

const (
	DefaultDirection Direction = iota
	Ascending
	Descending
)

Direction values.

func (Direction) String

func (d Direction) String() string

type Discard

type Discard struct {
	Mode DiscardMode
}

Discard represents a DISCARD statement.

func (*Discard) Format

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

Format implements the NodeFormatter interface.

func (*Discard) StatementTag

func (*Discard) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Discard) StatementType

func (*Discard) StatementType() StatementType

StatementType implements the Statement interface.

func (*Discard) String

func (node *Discard) String() string

String implements the Statement interface.

type DiscardMode

type DiscardMode int

DiscardMode is an enum of the various discard modes.

const (
	// DiscardModeAll represents a DISCARD ALL statement.
	DiscardModeAll DiscardMode = iota
)

type DropBehavior

type DropBehavior int

DropBehavior represents options for dropping schema elements.

const (
	DropDefault DropBehavior = iota
	DropRestrict
	DropCascade
)

DropBehavior values.

func (DropBehavior) String

func (d DropBehavior) String() string

type DropDatabase

type DropDatabase struct {
	Name     Name
	IfExists bool
}

DropDatabase represents a DROP DATABASE statement.

func (*DropDatabase) Format

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

Format implements the NodeFormatter interface.

func (*DropDatabase) StatementTag

func (*DropDatabase) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*DropDatabase) StatementType

func (*DropDatabase) StatementType() StatementType

StatementType implements the Statement interface.

func (*DropDatabase) String

func (n *DropDatabase) String() string

type DropIndex

type DropIndex struct {
	IndexList    TableNameWithIndexList
	IfExists     bool
	DropBehavior DropBehavior
}

DropIndex represents a DROP INDEX statement.

func (*DropIndex) Format

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

Format implements the NodeFormatter interface.

func (*DropIndex) StatementTag

func (*DropIndex) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*DropIndex) StatementType

func (*DropIndex) StatementType() StatementType

StatementType implements the Statement interface.

func (*DropIndex) String

func (n *DropIndex) String() string

type DropTable

type DropTable struct {
	Names        TableNameReferences
	IfExists     bool
	DropBehavior DropBehavior
}

DropTable represents a DROP TABLE statement.

func (*DropTable) Format

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

Format implements the NodeFormatter interface.

func (*DropTable) StatementTag

func (*DropTable) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*DropTable) StatementType

func (*DropTable) StatementType() StatementType

StatementType implements the Statement interface.

func (*DropTable) String

func (n *DropTable) String() string

type DropUser

type DropUser struct {
	Names    NameList
	IfExists bool
}

DropUser represents a DROP USER statement

func (*DropUser) Format

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

Format implements the NodeFormatter interface.

func (*DropUser) StatementTag

func (*DropUser) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*DropUser) StatementType

func (*DropUser) StatementType() StatementType

StatementType implements the Statement interface.

func (*DropUser) String

func (n *DropUser) String() string

type DropView

type DropView struct {
	Names        TableNameReferences
	IfExists     bool
	DropBehavior DropBehavior
}

DropView represents a DROP VIEW statement.

func (*DropView) Format

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

Format implements the NodeFormatter interface.

func (*DropView) StatementTag

func (*DropView) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*DropView) StatementType

func (*DropView) StatementType() StatementType

StatementType implements the Statement interface.

func (*DropView) String

func (n *DropView) String() string

type EvalContext

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

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

	Planner EvalPlanner

	ReCache *RegexpCache

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

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

	Mon *mon.MemoryMonitor

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

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

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

func MakeTestingEvalContext

func MakeTestingEvalContext() EvalContext

MakeTestingEvalContext returns an EvalContext that includes a MemoryMonitor.

func NewTestingEvalContext

func NewTestingEvalContext() *EvalContext

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

func (*EvalContext) GetClusterTimestamp

func (ctx *EvalContext) GetClusterTimestamp() *DDecimal

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

func (*EvalContext) GetClusterTimestampRaw

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

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

func (*EvalContext) GetLocation

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

GetLocation returns the session timezone.

func (*EvalContext) GetStmtTimestamp

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

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

func (*EvalContext) GetTxnTimestamp

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

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

func (*EvalContext) GetTxnTimestampNoZone

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

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

func (*EvalContext) GetTxnTimestampRaw

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

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

func (*EvalContext) NormalizeExpr

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

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

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

func (*EvalContext) SetClusterTimestamp

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

SetClusterTimestamp sets the corresponding timestamp in the EvalContext.

func (*EvalContext) SetStmtTimestamp

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

SetStmtTimestamp sets the corresponding timestamp in the EvalContext.

func (*EvalContext) SetTxnTimestamp

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

SetTxnTimestamp sets the corresponding timestamp in the EvalContext.

func (*EvalContext) Stop

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

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

type EvalPlanner

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

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

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

type Execute

type Execute struct {
	Name   Name
	Params Exprs
}

Execute represents an EXECUTE statement.

func (*Execute) Format

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

Format implements the NodeFormatter interface.

func (*Execute) StatementTag

func (*Execute) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Execute) StatementType

func (*Execute) StatementType() StatementType

StatementType implements the Statement interface.

func (*Execute) String

func (n *Execute) String() string

type ExistsExpr

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

ExistsExpr represents an EXISTS expression.

func (*ExistsExpr) Eval

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

Eval implements the TypedExpr interface.

func (*ExistsExpr) Format

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

Format implements the NodeFormatter interface.

func (ExistsExpr) ResolvedType

func (ta ExistsExpr) ResolvedType() Type

func (*ExistsExpr) String

func (node *ExistsExpr) String() string

func (*ExistsExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*ExistsExpr) Walk

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

Walk implements the Expr interface.

type Explain

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

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

Explain represents an EXPLAIN statement.

func (*Explain) CopyNode

func (stmt *Explain) CopyNode() *Explain

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

func (*Explain) Format

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

Format implements the NodeFormatter interface.

func (*Explain) StatementTag

func (*Explain) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Explain) StatementType

func (*Explain) StatementType() StatementType

StatementType implements the Statement interface.

func (*Explain) String

func (n *Explain) String() string

func (*Explain) WalkStmt

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

WalkStmt is part of the WalkableStmt interface.

type Expr

type Expr interface {
	fmt.Stringer
	NodeFormatter
	// Walk recursively walks all children using WalkExpr. If any children are changed, it returns a
	// copy of this node updated to point to the new children. Otherwise the receiver is returned.
	// For childless (leaf) Exprs, its implementation is empty.
	Walk(Visitor) Expr
	// TypeCheck transforms the Expr into a well-typed TypedExpr, which further permits
	// evaluation and type introspection, or an error if the expression cannot be well-typed.
	// When type checking is complete, if no error was reported, the expression and all
	// sub-expressions will be guaranteed to be well-typed, meaning that the method effectively
	// maps the Expr tree into a TypedExpr tree.
	//
	// The ctx parameter defines the context in which to perform type checking.
	// The desired parameter hints the desired type that the method's caller wants from
	// the resulting TypedExpr. It is not valid to call TypeCheck with a nil desired
	// type. Instead, call it with wildcard type TypeAny if no specific type is
	// desired. This restriction is also true of most methods and functions related
	// to type checking.
	TypeCheck(ctx *SemaContext, desired Type) (TypedExpr, error)
}

Expr represents an expression.

func ParseExpr

func ParseExpr(sql string) (Expr, error)

ParseExpr is a short-hand for parseExprs([]string{sql})

func SimpleVisit

func SimpleVisit(expr Expr, preFn SimpleVisitFn) (Expr, error)

SimpleVisit is a convenience wrapper for visitors that only have VisitPre code and don't return any results except an error. The given function is called in VisitPre for every node. The visitor stops as soon as an error is returned.

func StripParens

func StripParens(expr Expr) Expr

StripParens strips any parentheses surrounding an expression and returns the inner expression. For instance:

 1   -> 1
(1)  -> 1

((1)) -> 1

func WalkExpr

func WalkExpr(v Visitor, expr Expr) (newExpr Expr, changed bool)

WalkExpr traverses the nodes in an expression.

NOTE: Do not count on the WalkStmt/WalkExpr machinery to visit all expressions contained in a query. Only a sub-set of all expressions are found by WalkStmt and subsequently traversed. See the comment below on WalkStmt for details.

type Exprs

type Exprs []Expr

Exprs represents a list of value expressions. It's not a valid expression because it's not parenthesized.

func ParseExprs

func ParseExprs(sql []string) (Exprs, error)

ParseExprs is a short-hand for parseExprs(sql)

func (Exprs) Format

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

Format implements the NodeFormatter interface.

func (Exprs) String

func (node Exprs) String() string

type FamilyTableDef

type FamilyTableDef struct {
	Name    Name
	Columns NameList
}

FamilyTableDef represents a family definition within a CREATE TABLE statement.

func (*FamilyTableDef) Format

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

Format implements the NodeFormatter interface.

type FloatColType

type FloatColType struct {
	Name          string
	Prec          int
	Width         int
	PrecSpecified bool // true if the value of Prec is not the default
}

FloatColType represents a REAL, DOUBLE or FLOAT type.

func NewFloatColType

func NewFloatColType(prec int, precSpecified bool) *FloatColType

NewFloatColType creates a type representing a FLOAT, optionally with a precision.

func (*FloatColType) Format

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

Format implements the NodeFormatter interface.

func (*FloatColType) String

func (node *FloatColType) String() string

type FmtFlags

type FmtFlags *fmtFlags

FmtFlags enables conditional formatting in the pretty-printer.

var FmtAnonymize FmtFlags = &fmtFlags{anonymize: true}

FmtAnonymize instructs the pretty-printer to remove any name but function names. TODO(knz): temporary until a better solution is found for #13968

var FmtBareIdentifiers FmtFlags = &fmtFlags{bareIdentifiers: true}

FmtBareIdentifiers instructs the pretty-printer to print identifiers without wrapping quotes in any case.

var FmtBareStrings FmtFlags = &fmtFlags{bareStrings: true}

FmtBareStrings instructs the pretty-printer to print strings without wrapping quotes, if the string contains no special characters.

var FmtCheckEquivalence FmtFlags = &fmtFlags{symbolicVars: true, disambiguateDatumTypes: true}

FmtCheckEquivalence instructs the pretty-printer to produce a representation that can be used to check equivalence of expressions. Specifically:

  • IndexedVars are formatted using symbolic notation (to disambiguate columns).
  • datum types are disambiguated with explicit type annotations. This is necessary because datums of different types can otherwise be formatted to the same string: (for example the DDecimal 1 and the DInt 1).
var FmtHideConstants FmtFlags = &fmtFlags{hideConstants: true}

FmtHideConstants instructs the pretty-printer to produce a representation that does not disclose query-specific data.

var FmtParsable FmtFlags = &fmtFlags{disambiguateDatumTypes: true}

FmtParsable instructs the pretty-printer to produce a representation that can be parsed into an equivalent expression (useful for serialization of expressions).

var FmtShowTypes FmtFlags = &fmtFlags{showTypes: true}

FmtShowTypes instructs the pretty-printer to annotate expressions with their resolved types.

var FmtSimple FmtFlags = &fmtFlags{}

FmtSimple instructs the pretty-printer to produce a straightforward representation.

var FmtSimpleWithPasswords FmtFlags = &fmtFlags{showPasswords: true}

FmtSimpleWithPasswords instructs the pretty-printer to produce a straightforward representation that does not suppress passwords.

func FmtExpr

func FmtExpr(base FmtFlags, showTypes bool, symbolicVars bool, showTableAliases bool) FmtFlags

FmtExpr returns FmtFlags that indicate how the pretty-printer should format expressions.

func FmtIndexedVarFormat

func FmtIndexedVarFormat(
	base FmtFlags, fn func(buf *bytes.Buffer, f FmtFlags, c IndexedVarContainer, idx int),
) FmtFlags

FmtIndexedVarFormat returns FmtFlags that customizes the printing of IndexedVars using the provided function.

func FmtReformatTableNames

func FmtReformatTableNames(
	base FmtFlags, fn func(*NormalizableTableName, *bytes.Buffer, FmtFlags),
) FmtFlags

FmtReformatTableNames returns FmtFlags that instructs the pretty-printer to substitute the printing of table names using the provided function.

func FmtStarDatumFormat

func FmtStarDatumFormat(base FmtFlags, fn func(buf *bytes.Buffer, f FmtFlags)) FmtFlags

FmtStarDatumFormat returns FmtFlags that customizes the printing of StarDatums using the provided function.

type ForeignKeyConstraintTableDef

type ForeignKeyConstraintTableDef struct {
	Name     Name
	Table    NormalizableTableName
	FromCols NameList
	ToCols   NameList
}

ForeignKeyConstraintTableDef represents a FOREIGN KEY constraint in the AST.

func (*ForeignKeyConstraintTableDef) Format

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

Format implements the NodeFormatter interface.

type From

type From struct {
	Tables TableExprs
	AsOf   AsOfClause
}

From represents a FROM clause.

func (*From) Format

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

Format implements the NodeFormatter interface.

type FuncExpr

type FuncExpr struct {
	Func  ResolvableFunctionReference
	Type  funcType
	Exprs Exprs
	// Filter is used for filters on aggregates: SUM(k) FILTER (WHERE k > 0)
	Filter    Expr
	WindowDef *WindowDef
	// contains filtered or unexported fields
}

FuncExpr represents a function call.

func (*FuncExpr) CopyNode

func (expr *FuncExpr) CopyNode() *FuncExpr

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

func (*FuncExpr) Eval

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

Eval implements the TypedExpr interface.

func (*FuncExpr) Format

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

Format implements the NodeFormatter interface.

func (*FuncExpr) GetAggregateConstructor

func (node *FuncExpr) GetAggregateConstructor() func(*EvalContext) AggregateFunc

GetAggregateConstructor exposes the AggregateFunc field for use by the group node in package sql.

func (*FuncExpr) GetWindowConstructor

func (node *FuncExpr) GetWindowConstructor() func(*EvalContext) WindowFunc

GetWindowConstructor returns a window function constructor if the FuncExpr is a built-in window function.

func (*FuncExpr) IsDistSQLBlacklist

func (node *FuncExpr) IsDistSQLBlacklist() bool

IsDistSQLBlacklist returns whether the function is not supported by DistSQL.

func (*FuncExpr) IsImpure

func (node *FuncExpr) IsImpure() bool

IsImpure returns whether the function application is impure, meaning that it potentially returns a different value when called in the same statement with the same parameters.

func (*FuncExpr) IsWindowFunctionApplication

func (node *FuncExpr) IsWindowFunctionApplication() bool

IsWindowFunctionApplication returns if the function is being applied as a window function.

func (FuncExpr) ResolvedType

func (ta FuncExpr) ResolvedType() Type

func (*FuncExpr) String

func (node *FuncExpr) String() string

func (*FuncExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*FuncExpr) Walk

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

Walk implements the Expr interface.

type FunctionClass

type FunctionClass int

FunctionClass specifies the class of the builtin function.

const (
	// NormalClass is a standard builtin function.
	NormalClass FunctionClass = iota
	// AggregateClass is a builtin aggregate function.
	AggregateClass
	// WindowClass is a builtin window function.
	WindowClass
	// GeneratorClass is a builtin generator function.
	GeneratorClass
)

type FunctionDefinition

type FunctionDefinition struct {
	// Name is the short name of the function.
	Name string
	// HasOverloadsNeedingRepeatedEvaluation is true if one or more of
	// the overload definitions has needsRepeatedEvaluation set.
	// Set e.g. for aggregate functions.
	HasOverloadsNeedingRepeatedEvaluation bool
	// Definition is the set of overloads for this function name.
	Definition []overloadImpl
}

FunctionDefinition implements a reference to the (possibly several) overloads for a built-in function.

func (*FunctionDefinition) Format

func (fd *FunctionDefinition) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*FunctionDefinition) String

func (fd *FunctionDefinition) String() string

type FunctionReference

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

FunctionReference is the common interface to UnresolvedName and QualifiedFunctionName.

type Grant

type Grant struct {
	Privileges privilege.List
	Targets    TargetList
	Grantees   NameList
}

Grant represents a GRANT statement.

func (*Grant) Format

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

Format implements the NodeFormatter interface.

func (*Grant) StatementTag

func (*Grant) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Grant) StatementType

func (*Grant) StatementType() StatementType

StatementType implements the Statement interface.

func (*Grant) String

func (n *Grant) String() string

type GroupBy

type GroupBy []Expr

GroupBy represents a GROUP BY clause.

func (GroupBy) Format

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

Format implements the NodeFormatter interface.

type Help

type Help struct {
	Name Name
}

Help represents a HELP statement.

func (*Help) Format

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

Format implements the NodeFormatter interface.

func (*Help) StatementTag

func (*Help) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Help) StatementType

func (*Help) StatementType() StatementType

StatementType implements the Statement interface.

func (*Help) String

func (n *Help) String() string

type HiddenFromStats

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

HiddenFromStats is a pseudo-interface to be implemented by statements that should not show up in per-app statistics.

type HomogeneousType

type HomogeneousType struct{}

HomogeneousType is a typeList implementation that accepts any arguments, as long as all are the same type or NULL. The homogeneous constraint is enforced in typeCheckOverloadedExprs.

func (HomogeneousType) Length

func (HomogeneousType) Length() int

Length implements the typeList interface.

func (HomogeneousType) String

func (HomogeneousType) String() string

func (HomogeneousType) Types

func (HomogeneousType) Types() []Type

Types implements the typeList interface.

type ID

type ID uint32

ID is a custom type for {Database,Table}Descriptor IDs.

type IfExpr

type IfExpr struct {
	Cond Expr
	True Expr
	Else Expr
	// contains filtered or unexported fields
}

IfExpr represents an IF expression.

func (*IfExpr) Eval

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

Eval implements the TypedExpr interface.

func (*IfExpr) Format

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

Format implements the NodeFormatter interface.

func (IfExpr) ResolvedType

func (ta IfExpr) ResolvedType() Type

func (*IfExpr) String

func (node *IfExpr) String() string

func (*IfExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*IfExpr) TypedCondExpr

func (node *IfExpr) TypedCondExpr() TypedExpr

TypedCondExpr returns the IfExpr's Cond expression as a TypedExpr.

func (*IfExpr) TypedElseExpr

func (node *IfExpr) TypedElseExpr() TypedExpr

TypedElseExpr returns the IfExpr's Else expression as a TypedExpr.

func (*IfExpr) TypedTrueExpr

func (node *IfExpr) TypedTrueExpr() TypedExpr

TypedTrueExpr returns the IfExpr's True expression as a TypedExpr.

func (*IfExpr) Walk

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

Walk implements the Expr interface.

type IndependentFromParallelizedPriors

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

IndependentFromParallelizedPriors is a pseudo-interface to be implemented by statements which do not force parallel statement execution synchronization when they run.

type IndexElem

type IndexElem struct {
	Column    Name
	Direction Direction
}

IndexElem represents a column with a direction in a CREATE INDEX statement.

func (IndexElem) Format

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

Format implements the NodeFormatter interface.

type IndexElemList

type IndexElemList []IndexElem

IndexElemList is list of IndexElem.

func (IndexElemList) Format

func (l IndexElemList) Format(buf *bytes.Buffer, f FmtFlags)

Format pretty-prints the contained names separated by commas. Format implements the NodeFormatter interface.

type IndexHints

type IndexHints struct {
	Index       Name
	IndexID     IndexID
	NoIndexJoin bool
}

IndexHints represents "@<index_name>" or "@{param[,param]}" where param is one of:

  • FORCE_INDEX=<index_name>
  • NO_INDEX_JOIN

It is used optionally after a table name in SELECT statements.

func (*IndexHints) Format

func (n *IndexHints) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type IndexID

type IndexID uint32

IndexID is a custom type for IndexDescriptor IDs.

type IndexTableDef

type IndexTableDef struct {
	Name       Name
	Columns    IndexElemList
	Storing    NameList
	Interleave *InterleaveDef
}

IndexTableDef represents an index definition within a CREATE TABLE statement.

func (*IndexTableDef) Format

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

Format implements the NodeFormatter interface.

type IndexedRow

type IndexedRow struct {
	Idx int
	Row Datums
}

IndexedRow is a row with a corresponding index.

type IndexedVar

type IndexedVar struct {
	Idx int
	// contains filtered or unexported fields
}

IndexedVar is a VariableExpr that can be used as a leaf in expressions; it represents a dynamic value. It defers calls to TypeCheck, Eval, String to an IndexedVarContainer.

func NewIndexedVar

func NewIndexedVar(r int) *IndexedVar

NewIndexedVar is a helper routine to create a standalone Indexedvar with the given index value. This needs to undergo BindIfUnbound() below before it can be fully used. The difference with ordinal references is that vars returned by this constructor are modified in-place by BindIfUnbound.

Do not use NewIndexedVar for AST nodes that can undergo binding two or more times.

func NewOrdinalReference

func NewOrdinalReference(r int) *IndexedVar

NewOrdinalReference is a helper routine to create a standalone IndexedVar with the given index value. This needs to undergo BindIfUnbound() below before it can be fully used.

func (*IndexedVar) Eval

func (v *IndexedVar) Eval(ctx *EvalContext) (Datum, error)

Eval is part of the TypedExpr interface.

func (*IndexedVar) Format

func (v *IndexedVar) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*IndexedVar) ResolvedType

func (v *IndexedVar) ResolvedType() Type

ResolvedType is part of the TypedExpr interface.

func (*IndexedVar) String

func (node *IndexedVar) String() string

func (*IndexedVar) TypeCheck

func (v *IndexedVar) TypeCheck(_ *SemaContext, desired Type) (TypedExpr, error)

TypeCheck is part of the Expr interface.

func (*IndexedVar) Variable

func (*IndexedVar) Variable()

Variable is a dummy function part of the VariableExpr interface.

func (*IndexedVar) Walk

func (v *IndexedVar) Walk(_ Visitor) Expr

Walk is part of the Expr interface.

type IndexedVarContainer

type IndexedVarContainer interface {
	IndexedVarEval(idx int, ctx *EvalContext) (Datum, error)
	IndexedVarResolvedType(idx int) Type
	IndexedVarFormat(buf *bytes.Buffer, f FmtFlags, idx int)
}

IndexedVarContainer provides the implementation of TypeCheck, Eval, and String for IndexedVars. If an object that wishes to implement this interface has lost the textual name that an IndexedVar originates from, it can use the ordinal column reference syntax: fmt.Fprintf(buf, "@%d", idx)

type IndexedVarHelper

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

IndexedVarHelper wraps an IndexedVarContainer (an interface) and creates IndexedVars bound to that container.

It also keeps track of which indexes from the container are used by expressions.

func MakeIndexedVarHelper

func MakeIndexedVarHelper(container IndexedVarContainer, numVars int) IndexedVarHelper

MakeIndexedVarHelper initializes an IndexedVarHelper structure.

func (*IndexedVarHelper) AppendSlot

func (h *IndexedVarHelper) AppendSlot() int

AppendSlot expands the capacity of this IndexedVarHelper by one and returns the index of the new slot.

func (*IndexedVarHelper) BindIfUnbound

func (h *IndexedVarHelper) BindIfUnbound(ivar *IndexedVar) (*IndexedVar, error)

BindIfUnbound ensures the IndexedVar is attached to this helper's container. - for freshly created IndexedVars (with a nil container) this will bind in-place. - for already bound IndexedVar, bound to this container, this will return the same ivar unchanged. - for ordinal references (with an explicit unboundContainer) this will return a new var. - for already bound IndexedVars, bound to another container, this will error out.

func (*IndexedVarHelper) GetIndexedVars

func (h *IndexedVarHelper) GetIndexedVars() []IndexedVar

GetIndexedVars transfers ownership of the array of initialized IndexedVars to the caller; unused vars are guaranteed to have an invalid index. The helper cannot be used any more after the ownership has been transferred.

func (*IndexedVarHelper) IndexedVar

func (h *IndexedVarHelper) IndexedVar(idx int) *IndexedVar

IndexedVar returns an IndexedVar for the given index. The index must be valid.

func (*IndexedVarHelper) IndexedVarUsed

func (h *IndexedVarHelper) IndexedVarUsed(idx int) bool

IndexedVarUsed returns true if IndexedVar() was called for the given index. The index must be valid.

func (*IndexedVarHelper) NumVars

func (h *IndexedVarHelper) NumVars() int

NumVars returns the number of variables the IndexedVarHelper was initialized for.

func (*IndexedVarHelper) Rebind

func (h *IndexedVarHelper) Rebind(expr TypedExpr, alsoReset, normalizeToNonNil bool) TypedExpr

Rebind collects all the IndexedVars in the given expression and re-binds them to this helper.

func (*IndexedVarHelper) Reset

func (h *IndexedVarHelper) Reset()

Reset re-initializes an IndexedVarHelper structure with the same number of slots. After a helper has been reset, all the expressions that were linked to the helper before it was reset must be re-bound, e.g. using Rebind(). Resetting is useful to ensure that the helper's knowledge of which IndexedVars are actually used by linked expressions is up to date, especially after optimizations/transforms which eliminate sub-expressions. The optimizations performed by setNeededColumns() work then best.

TODO(knz): groupNode and windowNode hold on to IndexedVar's after a Reset().

func (*IndexedVarHelper) VisitPost

func (*IndexedVarHelper) VisitPost(expr Expr) Expr

VisitPost implements the Visitor interface.

func (*IndexedVarHelper) VisitPre

func (h *IndexedVarHelper) VisitPre(expr Expr) (recurse bool, newExpr Expr)

VisitPre implements the Visitor interface.

type IndirectionExpr

type IndirectionExpr struct {
	Expr        Expr
	Indirection ArraySubscripts
	// contains filtered or unexported fields
}

IndirectionExpr represents a subscript expression.

func (*IndirectionExpr) CopyNode

func (expr *IndirectionExpr) CopyNode() *IndirectionExpr

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

func (*IndirectionExpr) Eval

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

Eval implements the TypedExpr interface.

func (*IndirectionExpr) Format

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

Format implements the NodeFormatter interface.

func (IndirectionExpr) ResolvedType

func (ta IndirectionExpr) ResolvedType() Type

func (*IndirectionExpr) String

func (node *IndirectionExpr) String() string

func (*IndirectionExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*IndirectionExpr) Walk

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

Walk implements the Expr interface.

type Insert

type Insert struct {
	Table      TableExpr
	Columns    UnresolvedNames
	Rows       *Select
	OnConflict *OnConflict
	Returning  ReturningClause
}

Insert represents an INSERT statement.

func (*Insert) CopyNode

func (stmt *Insert) CopyNode() *Insert

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

func (*Insert) DefaultValues

func (node *Insert) DefaultValues() bool

DefaultValues returns true iff only default values are being inserted.

func (*Insert) Format

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

Format implements the NodeFormatter interface.

func (*Insert) StatementTag

func (*Insert) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Insert) StatementType

func (n *Insert) StatementType() StatementType

StatementType implements the Statement interface.

func (*Insert) String

func (n *Insert) String() string

func (*Insert) WalkStmt

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

WalkStmt is part of the WalkableStmt interface.

type IntColType

type IntColType struct {
	Name          string
	Width         int
	ImplicitWidth bool
}

IntColType represents an INT, INTEGER, SMALLINT or BIGINT type.

func (*IntColType) Format

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

Format implements the NodeFormatter interface.

func (*IntColType) IsSerial

func (node *IntColType) IsSerial() bool

IsSerial returns true when this column should be given a DEFAULT of a unique, incrementing function.

func (*IntColType) String

func (node *IntColType) String() string

type InterleaveDef

type InterleaveDef struct {
	Parent       NormalizableTableName
	Fields       NameList
	DropBehavior DropBehavior
}

InterleaveDef represents an interleave definition within a CREATE TABLE or CREATE INDEX statement.

func (*InterleaveDef) Format

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

Format implements the NodeFormatter interface.

type IntervalColType

type IntervalColType struct {
}

IntervalColType represents an INTERVAL type

func (*IntervalColType) Format

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

Format implements the NodeFormatter interface.

func (*IntervalColType) String

func (node *IntervalColType) String() string

type IsAggregateVisitor

type IsAggregateVisitor struct {
	Aggregated bool
	// contains filtered or unexported fields
}

IsAggregateVisitor checks if walked expressions contain aggregate functions.

func (*IsAggregateVisitor) Reset

func (v *IsAggregateVisitor) Reset()

Reset clear the IsAggregateVisitor's internal state.

func (*IsAggregateVisitor) VisitPost

func (*IsAggregateVisitor) VisitPost(expr Expr) Expr

VisitPost satisfies the Visitor interface.

func (*IsAggregateVisitor) VisitPre

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

VisitPre satisfies the Visitor interface.

type IsOfTypeExpr

type IsOfTypeExpr struct {
	Not   bool
	Expr  Expr
	Types []ColumnType
	// contains filtered or unexported fields
}

IsOfTypeExpr represents an IS {,NOT} OF (type_list) expression.

func (*IsOfTypeExpr) Eval

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

Eval implements the TypedExpr interface.

func (*IsOfTypeExpr) Format

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

Format implements the NodeFormatter interface.

func (IsOfTypeExpr) ResolvedType

func (ta IsOfTypeExpr) ResolvedType() Type

func (*IsOfTypeExpr) String

func (node *IsOfTypeExpr) String() string

func (*IsOfTypeExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*IsOfTypeExpr) Walk

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

Walk implements the Expr interface.

type IsolationLevel

type IsolationLevel int

IsolationLevel holds the isolation level for a transaction.

const (
	UnspecifiedIsolation IsolationLevel = iota
	SnapshotIsolation
	SerializableIsolation
)

IsolationLevel values

func (IsolationLevel) String

func (i IsolationLevel) String() string

type JoinCond

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

JoinCond represents a join condition.

type JoinTableExpr

type JoinTableExpr struct {
	Join  string
	Left  TableExpr
	Right TableExpr
	Cond  JoinCond
}

JoinTableExpr represents a TableExpr that's a JOIN operation.

func (*JoinTableExpr) Format

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

Format implements the NodeFormatter interface.

func (*JoinTableExpr) String

func (node *JoinTableExpr) String() string

type KVOption

type KVOption struct {
	Key   string
	Value string
}

KVOption is a key-value option.

type KVOptions

type KVOptions []KVOption

KVOptions is a list of KVOptions.

func (KVOptions) Format

func (o KVOptions) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (KVOptions) Get

func (o KVOptions) Get(key string) (string, bool)

Get returns first value for requested key and if it was found or not.

type Limit

type Limit struct {
	Offset, Count Expr
}

Limit represents a LIMIT clause.

func (*Limit) Format

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

Format implements the NodeFormatter interface.

type MaxAggregate

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

MaxAggregate keeps track of the largest value passed to Add.

func (*MaxAggregate) Add

func (a *MaxAggregate) Add(_ context.Context, datum Datum) error

Add sets the max to the larger of the current max or the passed datum.

func (*MaxAggregate) Close

func (a *MaxAggregate) Close(context.Context)

Close is part of the AggregateFunc interface.

func (*MaxAggregate) Result

func (a *MaxAggregate) Result() (Datum, error)

Result returns the largest value passed to Add.

type MinAggregate

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

MinAggregate keeps track of the smallest value passed to Add.

func (*MinAggregate) Add

func (a *MinAggregate) Add(_ context.Context, datum Datum) error

Add sets the min to the smaller of the current min or the passed datum.

func (*MinAggregate) Close

func (a *MinAggregate) Close(context.Context)

Close is part of the AggregateFunc interface.

func (*MinAggregate) Result

func (a *MinAggregate) Result() (Datum, error)

Result returns the smallest value passed to Add.

type MultipleResultsError

type MultipleResultsError struct {
	SQL string // the query that produced this error
}

MultipleResultsError is returned by QueryRow when more than one result is encountered.

func (*MultipleResultsError) Error

func (e *MultipleResultsError) Error() string

type Name

type Name string

A Name is an SQL identifier.

func (Name) Format

func (n Name) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (Name) Normalize

func (n Name) Normalize() string

Normalize normalizes to lowercase and Unicode Normalization Form C (NFC).

func (Name) String

func (node Name) String() string

type NameColType

type NameColType struct{}

NameColType represents a a NAME type.

func (*NameColType) Format

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

Format implements the NodeFormatter interface.

func (*NameColType) String

func (node *NameColType) String() string

type NameList

type NameList []Name

A NameList is a list of identifiers.

func (NameList) Format

func (l NameList) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (NameList) String

func (list NameList) String() string

func (NameList) ToStrings

func (l NameList) ToStrings() []string

ToStrings converts the name list to an array of regular strings.

type NamePart

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

NamePart is the interface for the sub-parts of an UnresolvedName or the Selector/Context members of ColumnItem and FunctionName.

type NameParts

type NameParts []NamePart

NameParts represents a combination of names with array and sub-field subscripts.

func (NameParts) Format

func (l NameParts) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type NamedColumnQualification

type NamedColumnQualification struct {
	Name          Name
	Qualification ColumnQualification
}

NamedColumnQualification wraps a NamedColumnQualification with a name.

type NaturalJoinCond

type NaturalJoinCond struct{}

NaturalJoinCond represents a NATURAL join condition

func (NaturalJoinCond) Format

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

Format implements the NodeFormatter interface.

type NoReturningClause

type NoReturningClause struct{}

NoReturningClause represents the absence of a RETURNING clause.

func (*NoReturningClause) Format

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

Format implements the NodeFormatter interface.

type NodeFormatter

type NodeFormatter interface {
	// Format performs pretty-printing towards a bytes buffer. The flags argument
	// influences the results. Most callers should use FormatNode instead.
	Format(buf *bytes.Buffer, flags FmtFlags)
}

NodeFormatter is implemented by nodes that can be pretty-printed.

type NormalizableTableName

type NormalizableTableName struct {
	TableNameReference
}

NormalizableTableName implements an editable table name.

func (NormalizableTableName) Format

func (nt NormalizableTableName) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*NormalizableTableName) Normalize

func (nt *NormalizableTableName) Normalize() (*TableName, error)

Normalize checks if the table name is already normalized and normalizes it as necessary.

func (*NormalizableTableName) NormalizeWithDatabaseName

func (nt *NormalizableTableName) NormalizeWithDatabaseName(database string) (*TableName, error)

NormalizeWithDatabaseName combines Normalize and QualifyWithDatabase.

func (NormalizableTableName) String

func (nt NormalizableTableName) String() string

func (*NormalizableTableName) TableName

func (nt *NormalizableTableName) TableName() *TableName

TableName asserts that the table name has been previously normalized.

type NotExpr

type NotExpr struct {
	Expr Expr
	// contains filtered or unexported fields
}

NotExpr represents a NOT expression.

func NewTypedNotExpr

func NewTypedNotExpr(expr TypedExpr) *NotExpr

NewTypedNotExpr returns a new NotExpr that is verified to be well-typed.

func (*NotExpr) Eval

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

Eval implements the TypedExpr interface.

func (*NotExpr) Format

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

Format implements the NodeFormatter interface.

func (NotExpr) ResolvedType

func (ta NotExpr) ResolvedType() Type

func (*NotExpr) String

func (node *NotExpr) String() string

func (*NotExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*NotExpr) TypedInnerExpr

func (node *NotExpr) TypedInnerExpr() TypedExpr

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

func (*NotExpr) Walk

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

Walk implements the Expr interface.

type NotNullConstraint

type NotNullConstraint struct{}

NotNullConstraint represents NOT NULL on a column.

type NullConstraint

type NullConstraint struct{}

NullConstraint represents NULL on a column.

type NullIfExpr

type NullIfExpr struct {
	Expr1 Expr
	Expr2 Expr
	// contains filtered or unexported fields
}

NullIfExpr represents a NULLIF expression.

func (*NullIfExpr) Eval

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

Eval implements the TypedExpr interface.

func (*NullIfExpr) Format

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

Format implements the NodeFormatter interface.

func (NullIfExpr) ResolvedType

func (ta NullIfExpr) ResolvedType() Type

func (*NullIfExpr) String

func (node *NullIfExpr) String() string

func (*NullIfExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*NullIfExpr) Walk

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

Walk implements the Expr interface.

type Nullability

type Nullability int

Nullability represents either NULL, NOT NULL or an unspecified value (silent NULL).

const (
	NotNull Nullability = iota
	Null
	SilentNull
)

The values for NullType.

type NumVal

type NumVal struct {
	constant.Value

	// We preserve the "original" string representation (before folding).
	OrigString string
	// contains filtered or unexported fields
}

NumVal represents a constant numeric value.

func (*NumVal) AsInt64

func (expr *NumVal) AsInt64() (int64, error)

AsInt64 returns the value as a 64-bit integer if possible, or returns an error if not possible. The method will set expr.resInt to the value of this int64 if it is successful, avoiding the need to call the method again.

func (*NumVal) AvailableTypes

func (expr *NumVal) AvailableTypes() []Type

AvailableTypes implements the Constant interface.

func (*NumVal) Format

func (expr *NumVal) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*NumVal) ResolveAsType

func (expr *NumVal) ResolveAsType(ctx *SemaContext, typ Type) (Datum, error)

ResolveAsType implements the Constant interface.

func (*NumVal) ShouldBeInt64

func (expr *NumVal) ShouldBeInt64() bool

ShouldBeInt64 checks if the value naturally is an int64:

1   = yes
1.0 = no
1.1 = no
123...overflow...456 = no

Currently unused so commented out, but useful even just for its documentation value.

func (*NumVal) String

func (node *NumVal) String() string

func (*NumVal) TypeCheck

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

TypeCheck implements the Expr interface.

func (*NumVal) Walk

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

Walk implements the Expr interface.

type OidColType

type OidColType struct {
	Name string
}

OidColType represents an OID type, which is the type of system object identifiers. There are several different OID types: the raw OID type, which can be any integer, and the reg* types, each of which corresponds to the particular system table that contains the system object identified by the OID itself.

See https://www.postgresql.org/docs/9.6/static/datatype-oid.html.

func (*OidColType) Format

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

Format implements the NodeFormatter interface.

func (*OidColType) String

func (node *OidColType) String() string

type OnConflict

type OnConflict struct {
	Columns   NameList
	Exprs     UpdateExprs
	Where     *Where
	DoNothing bool
}

OnConflict represents an `ON CONFLICT (columns) DO UPDATE SET exprs WHERE where` clause.

The zero value for OnConflict is used to signal the UPSERT short form, which uses the primary key for as the conflict index and the values being inserted for Exprs.

func (*OnConflict) IsUpsertAlias

func (oc *OnConflict) IsUpsertAlias() bool

IsUpsertAlias returns true if the UPSERT syntactic sugar was used.

type OnJoinCond

type OnJoinCond struct {
	Expr Expr
}

OnJoinCond represents an ON join condition.

func (*OnJoinCond) Format

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

Format implements the NodeFormatter interface.

type OrExpr

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

OrExpr represents an OR expression.

func NewTypedOrExpr

func NewTypedOrExpr(left, right TypedExpr) *OrExpr

NewTypedOrExpr returns a new OrExpr that is verified to be well-typed.

func (*OrExpr) Eval

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

Eval implements the TypedExpr interface.

func (*OrExpr) Format

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

Format implements the NodeFormatter interface.

func (OrExpr) ResolvedType

func (ta OrExpr) ResolvedType() Type

func (*OrExpr) String

func (node *OrExpr) String() string

func (*OrExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*OrExpr) TypedLeft

func (node *OrExpr) TypedLeft() TypedExpr

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

func (*OrExpr) TypedRight

func (node *OrExpr) TypedRight() TypedExpr

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

func (*OrExpr) Walk

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

Walk implements the Expr interface.

type Order

type Order struct {
	OrderType OrderType
	Expr      Expr
	Direction Direction
	// Table/Index replaces Expr when OrderType = OrderByIndex.
	Table NormalizableTableName
	// If Index is empty, then the order should use the primary key.
	Index Name
}

Order represents an ordering expression.

func (*Order) Format

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

Format implements the NodeFormatter interface.

type OrderBy

type OrderBy []*Order

OrderBy represents an ORDER By clause.

func (OrderBy) Format

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

Format implements the NodeFormatter interface.

type OrderType

type OrderType int

OrderType indicates which type of expression is used in ORDER BY.

const (
	// OrderByColumn is the regular "by expression/column" ORDER BY specification.
	OrderByColumn OrderType = iota
	// OrderByIndex enables the user to specify a given index' columns implicitly.
	OrderByIndex
)

type ParenExpr

type ParenExpr struct {
	Expr Expr
	// contains filtered or unexported fields
}

ParenExpr represents a parenthesized expression.

func (*ParenExpr) Eval

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

Eval implements the TypedExpr interface.

func (*ParenExpr) Format

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

Format implements the NodeFormatter interface.

func (ParenExpr) ResolvedType

func (ta ParenExpr) ResolvedType() Type

func (*ParenExpr) String

func (node *ParenExpr) String() string

func (*ParenExpr) TypeCheck

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

TypeCheck implements the Expr interface.

func (*ParenExpr) TypedInnerExpr

func (node *ParenExpr) TypedInnerExpr() TypedExpr

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

func (*ParenExpr) Walk

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

Walk implements the Expr interface.

type ParenSelect

type ParenSelect struct {
	Select *Select
}

ParenSelect represents a parenthesized SELECT/UNION/VALUES statement.

func (*ParenSelect) Format

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

Format implements the NodeFormatter interface.

func (*ParenSelect) StatementTag

func (*ParenSelect) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*ParenSelect) StatementType

func (*ParenSelect) StatementType() StatementType

StatementType implements the Statement interface.

func (*ParenSelect) String

func (n *ParenSelect) String() string

func (*ParenSelect) WalkStmt

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

WalkStmt is part of the WalkableStmt interface.

type ParenTableExpr

type ParenTableExpr struct {
	Expr TableExpr
}

ParenTableExpr represents a parenthesized TableExpr.

func (*ParenTableExpr) Format

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

Format implements the NodeFormatter interface.

func (*ParenTableExpr) String

func (node *ParenTableExpr) String() string

type Parser

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

Parser wraps a scanner, parser and other utilities present in the parser package.

func (*Parser) AggregateInExpr

func (p *Parser) AggregateInExpr(expr Expr, searchPath SearchPath) bool

AggregateInExpr determines if an Expr contains an aggregate function.

func (*Parser) AssertNoAggregationOrWindowing

func (p *Parser) AssertNoAggregationOrWindowing(expr Expr, op string, searchPath SearchPath) error

AssertNoAggregationOrWindowing checks if the provided expression contains either aggregate functions or window functions, returning an error in either case.

func (*Parser) IsAggregate

func (p *Parser) IsAggregate(n *SelectClause, searchPath SearchPath) bool

IsAggregate determines if SelectClause contains an aggregate function.

func (*Parser) NormalizeExpr

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

NormalizeExpr is wrapper around ctx.NormalizeExpr which avoids allocation of a normalizeVisitor.

func (*Parser) Parse

func (p *Parser) Parse(sql string) (stmts StatementList, err error)

Parse parses the sql and returns a list of statements.

func (*Parser) WindowFuncInExpr

func (p *Parser) WindowFuncInExpr(expr Expr) bool

WindowFuncInExpr determines if an Expr contains a window function, using the Parser's embedded visitor.

func (*Parser) WindowFuncInExprs

func (p *Parser) WindowFuncInExprs(exprs []TypedExpr) bool

WindowFuncInExprs determines if any of the provided TypedExpr contains a window function, using the Parser's embedded visitor.

type PauseJob

type PauseJob struct {
	ID Expr
}

PauseJob represents a PAUSE JOB statement.

func (*PauseJob) Format

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

Format implements the NodeFormatter interface.

func (*PauseJob) StatementTag

func (*PauseJob) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*PauseJob) StatementType

func (*PauseJob) StatementType() StatementType

StatementType implements the Statement interface.

func (*PauseJob) String

func (n *PauseJob) String() string

type Placeholder

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

Placeholder represents a named placeholder.

func NewPlaceholder

func NewPlaceholder(name string) *Placeholder

NewPlaceholder allocates a Placeholder.

func (*Placeholder) Eval

func (node *Placeholder) Eval(_ *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*Placeholder) Format

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

Format implements the NodeFormatter interface.

func (*Placeholder) ResolvedType

func (node *Placeholder) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*Placeholder) String

func (node *Placeholder) String() string

func (*Placeholder) TypeCheck

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

TypeCheck implements the Expr interface.

func (*Placeholder) Variable

func (*Placeholder) Variable()

Variable implements the VariableExpr interface.

func (*Placeholder) Walk

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

Walk implements the Expr interface.

type PlaceholderInfo

type PlaceholderInfo struct {
	Values QueryArguments
	Types  PlaceholderTypes
}

PlaceholderInfo defines the interface to SQL placeholders.

func MakePlaceholderInfo

func MakePlaceholderInfo() PlaceholderInfo

MakePlaceholderInfo constructs an empty PlaceholderInfo.

func (*PlaceholderInfo) AssertAllAssigned

func (p *PlaceholderInfo) AssertAllAssigned() error

AssertAllAssigned ensures that all placeholders that are used also have a value assigned.

func (*PlaceholderInfo) Assign

func (p *PlaceholderInfo) Assign(src *PlaceholderInfo)

Assign resets the PlaceholderInfo to the contents of src. If src is nil, the map is cleared.

func (*PlaceholderInfo) Clear

func (p *PlaceholderInfo) Clear()

Clear resets the placeholder info map.

func (*PlaceholderInfo) FillUnassigned

func (p *PlaceholderInfo) FillUnassigned()

FillUnassigned sets all unsassigned placeholders to NULL.

func (*PlaceholderInfo) IsUnresolvedPlaceholder

func (p *PlaceholderInfo) IsUnresolvedPlaceholder(expr Expr) bool

IsUnresolvedPlaceholder returns whether expr is an unresolved placeholder. In other words, it returns whether the provided expression is a placeholder expression or a placeholder expression within nested parentheses, and if so, whether the placeholder's type remains unset in the PlaceholderInfo.

func (*PlaceholderInfo) SetType

func (p *PlaceholderInfo) SetType(name string, typ Type) error

SetType assignes a known type to a placeholder. Reports an error if another type was previously assigned.

func (*PlaceholderInfo) SetTypes

func (p *PlaceholderInfo) SetTypes(src PlaceholderTypes)

SetTypes resets the type and values in the map and replaces the types map by an alias to src. If src is nil, the map is cleared. The types map is aliased because the invoking code from pgwire/v3.go for sql.Prepare needs to receive the updated type assignments after Prepare completes.

func (*PlaceholderInfo) SetValue

func (p *PlaceholderInfo) SetValue(name string, val Datum)

SetValue assigns a known value to a placeholder. If no type is known yet, it is inferred from the assigned value.

func (*PlaceholderInfo) Type

func (p *PlaceholderInfo) Type(name string) (Type, bool)

Type returns the known type of a placeholder. Returns false in the 2nd value if the placeholder is not typed.

func (*PlaceholderInfo) Value

func (p *PlaceholderInfo) Value(name string) (TypedExpr, bool)

Value returns the known value of a placeholder. Returns false in the 2nd value if the placeholder does not have a value.

type PlaceholderTypes

type PlaceholderTypes map[string]Type

PlaceholderTypes relates placeholder names to their resolved type.

func (PlaceholderTypes) ProcessPlaceholderAnnotations

func (p PlaceholderTypes) ProcessPlaceholderAnnotations(stmt Statement) error

ProcessPlaceholderAnnotations performs an order-independent global traversal of the provided Statement, annotating all placeholders with a type in either of the following situations.

  • the placeholder is the subject of an explicit type annotation in at least one of its occurrences. If it is subject to multiple explicit type annotations where the types are not all in agreement, or if the placeholder already has an inferred type in the placeholder map which conflicts with the explicit type annotation type, an error will be thrown.
  • the placeholder is the subject to an implicit type annotation, meaning that it is not subject to an explicit type annotation, and that in all occurrences of the placeholder, it is subject to a cast to the same type. If it is subject to casts of multiple types, no error will be thrown, but the placeholder type will not be inferred. If a type has already been assigned for the placeholder in the placeholder map, no error will be thrown, and the placeholder will keep it's previously inferred type.

TODO(nvanbenschoten): Can this visitor and map be preallocated (like normalizeVisitor)?

type Prepare

type Prepare struct {
	Name      Name
	Types     []ColumnType
	Statement Statement
}

Prepare represents a PREPARE statement.

func (*Prepare) Format

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

Format implements the NodeFormatter interface.

func (*Prepare) StatementTag

func (*Prepare) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Prepare) StatementType

func (*Prepare) StatementType() StatementType

StatementType implements the Statement interface.

func (*Prepare) String

func (n *Prepare) String() string

type PrimaryKeyConstraint

type PrimaryKeyConstraint struct{}

PrimaryKeyConstraint represents NULL on a column.

type QueryArguments

type QueryArguments map[string]TypedExpr

QueryArguments relates placeholder names to their provided query argument.

type RangeCond

type RangeCond struct {
	Not      bool
	Left     Expr
	From, To Expr
	// contains filtered or unexported fields
}

RangeCond represents a BETWEEN or a NOT BETWEEN expression.

func (*RangeCond) Eval

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

Eval implements the TypedExpr interface.

func (*RangeCond) Format

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

Format implements the NodeFormatter interface.

func (RangeCond) ResolvedType

func (ta RangeCond) ResolvedType() Type

func (*RangeCond) String

func (node *RangeCond) String() string

func (*RangeCond) TypeCheck

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

TypeCheck implements the Expr interface.

func (*RangeCond) TypedFrom

func (node *RangeCond) TypedFrom() TypedExpr

TypedFrom returns the RangeCond's from expression as a TypedExpr.

func (*RangeCond) TypedLeft

func (node *RangeCond) TypedLeft() TypedExpr

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

func (*RangeCond) TypedTo

func (node *RangeCond) TypedTo() TypedExpr

TypedTo returns the RangeCond's to expression as a TypedExpr.

func (*RangeCond) Walk

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

Walk implements the Expr interface.

type ReadWriteMode

type ReadWriteMode int

ReadWriteMode holds the read write mode for a transaction.

const (
	UnspecifiedReadWriteMode ReadWriteMode = iota
	ReadOnly
	ReadWrite
)

ReadWriteMode values

func (ReadWriteMode) String

func (ro ReadWriteMode) String() string

type RegexpCache

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

A RegexpCache is a cache used to store compiled regular expressions. The cache is safe for concurrent use by multiple goroutines. It is also safe to use the cache through a nil reference, where it will act like a valid cache with no capacity.

func NewRegexpCache

func NewRegexpCache(size int) *RegexpCache

NewRegexpCache creates a new RegexpCache of the given size. The underlying cache internally uses a hash map, so lookups are cheap.

func (*RegexpCache) GetRegexp

func (rc *RegexpCache) GetRegexp(key regexpCacheKey) (*regexp.Regexp, error)

GetRegexp consults the cache for the regular expressions stored for the given key, compiling the key's pattern if it is not already in the cache.

func (*RegexpCache) Len

func (rc *RegexpCache) Len() int

Len returns the number of compiled regular expressions in the cache.

type ReleaseSavepoint

type ReleaseSavepoint struct {
	Savepoint string
}

ReleaseSavepoint represents a RELEASE SAVEPOINT <name> statement.

func (*ReleaseSavepoint) Format

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

Format implements the NodeFormatter interface.

func (*ReleaseSavepoint) StatementTag

func (*ReleaseSavepoint) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*ReleaseSavepoint) StatementType

func (*ReleaseSavepoint) StatementType() StatementType

StatementType implements the Statement interface.

func (*ReleaseSavepoint) String

func (n *ReleaseSavepoint) String() string

type RenameColumn

type RenameColumn struct {
	Table   NormalizableTableName
	Name    Name
	NewName Name
	// IfExists refers to the table, not the column.
	IfExists bool
}

RenameColumn represents a RENAME COLUMN statement.

func (*RenameColumn) Format

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

Format implements the NodeFormatter interface.

func (*RenameColumn) StatementTag

func (*RenameColumn) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*RenameColumn) StatementType

func (*RenameColumn) StatementType() StatementType

StatementType implements the Statement interface.

func (*RenameColumn) String

func (n *RenameColumn) String() string

type RenameDatabase

type RenameDatabase struct {
	Name    Name
	NewName Name
}

RenameDatabase represents a RENAME DATABASE statement.

func (*RenameDatabase) Format

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

Format implements the NodeFormatter interface.

func (*RenameDatabase) StatementTag

func (*RenameDatabase) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*RenameDatabase) StatementType

func (*RenameDatabase) StatementType() StatementType

StatementType implements the Statement interface.

func (*RenameDatabase) String

func (n *RenameDatabase) String() string

type RenameIndex

type RenameIndex struct {
	Index    *TableNameWithIndex
	NewName  Name
	IfExists bool
}

RenameIndex represents a RENAME INDEX statement.

func (*RenameIndex) Format

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

Format implements the NodeFormatter interface.

func (*RenameIndex) StatementTag

func (*RenameIndex) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*RenameIndex) StatementType

func (*RenameIndex) StatementType() StatementType

StatementType implements the Statement interface.

func (*RenameIndex) String

func (n *RenameIndex) String() string

type RenameTable

type RenameTable struct {
	Name     NormalizableTableName
	NewName  NormalizableTableName
	IfExists bool
	IsView   bool
}

RenameTable represents a RENAME TABLE or RENAME VIEW statement. Whether the user has asked to rename a table or view is indicated by the IsView field.

func (*RenameTable) Format

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

Format implements the NodeFormatter interface.

func (*RenameTable) StatementTag

func (n *RenameTable) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*RenameTable) StatementType

func (*RenameTable) StatementType() StatementType

StatementType implements the Statement interface.

func (*RenameTable) String

func (n *RenameTable) String() string

type ResolvableFunctionReference

type ResolvableFunctionReference struct {
	FunctionReference
}

ResolvableFunctionReference implements the editable reference cell of a FuncExpr. The FunctionRerence is updated by the Normalize() method.

func (ResolvableFunctionReference) Format

func (fn ResolvableFunctionReference) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*ResolvableFunctionReference) Resolve

func (fn *ResolvableFunctionReference) Resolve(searchPath SearchPath) (*FunctionDefinition, error)

Resolve checks if the function name is already resolved and resolves it as necessary.

func (ResolvableFunctionReference) String

func (fn ResolvableFunctionReference) String() string

type Restore

type Restore struct {
	Targets TargetList
	From    Exprs
	AsOf    AsOfClause
	Options KVOptions
}

Restore represents a RESTORE statement.

func (*Restore) Format

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

Format implements the NodeFormatter interface.

func (*Restore) StatementTag

func (*Restore) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Restore) StatementType

func (*Restore) StatementType() StatementType

StatementType implements the Statement interface.

func (*Restore) String

func (n *Restore) String() string

type ResumeJob

type ResumeJob struct {
	ID Expr
}

ResumeJob represents a RESUME JOB statement.

func (*ResumeJob) Format

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

Format implements the NodeFormatter interface.

func (*ResumeJob) StatementTag

func (*ResumeJob) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*ResumeJob) StatementType

func (*ResumeJob) StatementType() StatementType

StatementType implements the Statement interface.

func (*ResumeJob) String

func (n *ResumeJob) String() string

type ReturningClause

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

ReturningClause represents the returning clause on a statement.

type ReturningExprs

type ReturningExprs SelectExprs

ReturningExprs represents RETURNING expressions.

func (*ReturningExprs) CopyNode

func (stmt *ReturningExprs) CopyNode() *ReturningExprs

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

func (*ReturningExprs) Format

func (r *ReturningExprs) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type ReturningNothing

type ReturningNothing struct{}

ReturningNothing represents RETURNING NOTHING.

func (*ReturningNothing) Format

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

Format implements the NodeFormatter interface.

type Revoke

type Revoke struct {
	Privileges privilege.List
	Targets    TargetList
	Grantees   NameList
}

Revoke represents a REVOKE statements. PrivilegeList and TargetList are defined in grant.go

func (*Revoke) Format

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

Format implements the NodeFormatter interface.

func (*Revoke) StatementTag

func (*Revoke) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Revoke) StatementType

func (*Revoke) StatementType() StatementType

StatementType implements the Statement interface.

func (*Revoke) String

func (n *Revoke) String() string

type RollbackToSavepoint

type RollbackToSavepoint struct {
	Savepoint string
}

RollbackToSavepoint represents a ROLLBACK TO SAVEPOINT <name> statement.

func (*RollbackToSavepoint) Format

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

Format implements the NodeFormatter interface.

func (*RollbackToSavepoint) StatementTag

func (*RollbackToSavepoint) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*RollbackToSavepoint) StatementType

func (*RollbackToSavepoint) StatementType() StatementType

StatementType implements the Statement interface.

func (*RollbackToSavepoint) String

func (n *RollbackToSavepoint) String() string

type RollbackTransaction

type RollbackTransaction struct{}

RollbackTransaction represents a ROLLBACK statement.

func (*RollbackTransaction) Format

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

Format implements the NodeFormatter interface.

func (*RollbackTransaction) StatementTag

func (*RollbackTransaction) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*RollbackTransaction) StatementType

func (*RollbackTransaction) StatementType() StatementType

StatementType implements the Statement interface.

func (*RollbackTransaction) String

func (n *RollbackTransaction) String() string

type Savepoint

type Savepoint struct {
	Name string
}

Savepoint represents a SAVEPOINT <name> statement.

func (*Savepoint) Format

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

Format implements the NodeFormatter interface.

func (*Savepoint) StatementTag

func (*Savepoint) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Savepoint) StatementType

func (*Savepoint) StatementType() StatementType

StatementType implements the Statement interface.

func (*Savepoint) String

func (n *Savepoint) String() string

type Scanner

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

Scanner lexes SQL statements.

func MakeScanner

func MakeScanner(str string) Scanner

MakeScanner makes a Scanner from str.

func (*Scanner) Error

func (s *Scanner) Error(e string)

func (*Scanner) Lex

func (s *Scanner) Lex(lval *sqlSymType) int

Lex lexes a token from input.

func (*Scanner) Tokens

func (s *Scanner) Tokens(f func(token int))

Tokens calls f on all tokens of the input until an EOF is encountered.

func (*Scanner) Unimplemented

func (s *Scanner) Unimplemented(feature string)

Unimplemented wraps Error, setting lastUnimplementedError.

func (*Scanner) UnimplementedWithIssue

func (s *Scanner) UnimplementedWithIssue(issue int)

UnimplementedWithIssue wraps Error, setting lastUnimplementedError.

type Scatter

type Scatter struct {
	// Only one of Table and Index can be set.
	Table *NormalizableTableName
	Index *TableNameWithIndex
	// Optional from and to values for the columns in the PK or index (or a prefix
	// of the columns).
	// See docs/RFCS/sql_split_syntax.md.
	From, To Exprs
}

Scatter represents an `ALTER TABLE/INDEX .. SCATTER ..` statement.

func (*Scatter) Format

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

Format implements the NodeFormatter interface.

func (*Scatter) StatementTag

func (*Scatter) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Scatter) StatementType

func (*Scatter) StatementType() StatementType

StatementType implements the Statement interface.

func (*Scatter) String

func (n *Scatter) String() string

type SearchPath

type SearchPath []string

SearchPath represents a list of namespaces to search builtins in. The names must be normalized (as per Name.Normalize) already.

type Select

type Select struct {
	Select  SelectStatement
	OrderBy OrderBy
	Limit   *Limit
}

Select represents a SelectStatement with an ORDER and/or LIMIT.

func (*Select) CopyNode

func (stmt *Select) CopyNode() *Select

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

func (*Select) Format

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

Format implements the NodeFormatter interface.

func (*Select) StatementTag

func (*Select) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Select) StatementType

func (*Select) StatementType() StatementType

StatementType implements the Statement interface.

func (*Select) String

func (n *Select) String() string

func (*Select) WalkStmt

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

WalkStmt is part of the WalkableStmt interface.

type SelectClause

type SelectClause struct {
	Distinct bool
	Exprs    SelectExprs
	From     *From
	Where    *Where
	GroupBy  GroupBy
	Having   *Where
	Window   Window
	// contains filtered or unexported fields
}

SelectClause represents a SELECT statement.

func (*SelectClause) CopyNode

func (stmt *SelectClause) CopyNode() *SelectClause

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

func (*SelectClause) Format

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

Format implements the NodeFormatter interface.

func (*SelectClause) StatementTag

func (*SelectClause) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*SelectClause) StatementType

func (*SelectClause) StatementType() StatementType

StatementType implements the Statement interface.

func (*SelectClause) String

func (n *SelectClause) String() string

func (*SelectClause) WalkStmt

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

WalkStmt is part of the WalkableStmt interface.

type SelectExpr

type SelectExpr struct {
	Expr Expr
	As   Name
}

SelectExpr represents a SELECT expression.

func (SelectExpr) Format

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

Format implements the NodeFormatter interface.

func (*SelectExpr) NormalizeTopLevelVarName

func (node *SelectExpr) NormalizeTopLevelVarName() error

NormalizeTopLevelVarName preemptively expands any UnresolvedName at the top level of the expression into a VarName. This is meant to catch stars so that sql.checkRenderStar() can see it prior to other expression transformations.

type SelectExprs

type SelectExprs []SelectExpr

SelectExprs represents SELECT expressions.

func (SelectExprs) Format

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

Format implements the NodeFormatter interface.

type SelectStatement

type SelectStatement interface {
	Statement
	// contains filtered or unexported methods
}

SelectStatement represents any SELECT statement.

type SemaContext

type SemaContext struct {
	// Placeholders relates placeholder names to their type and, later, value.
	Placeholders PlaceholderInfo

	// Location references the *Location on the current Session.
	Location **time.Location

	// SearchPath indicates where to search for unqualified function
	// names. The path elements must be normalized via Name.Normalize()
	// already.
	SearchPath []string
	// contains filtered or unexported fields
}

SemaContext defines the context in which to perform semantic analysis on an expression syntax tree.

func MakeSemaContext

func MakeSemaContext(privileged bool) SemaContext

MakeSemaContext initializes a simple SemaContext suitable for "lightweight" type checking such as the one performed for default expressions.

type Set

type Set struct {
	Name    VarName
	Values  Exprs
	SetMode SetMode
}

Set represents a SET or RESET statement.

func (*Set) CopyNode

func (stmt *Set) CopyNode() *Set

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

func (*Set) Format

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

Format implements the NodeFormatter interface.

func (*Set) StatementTag

func (*Set) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Set) StatementType

func (*Set) StatementType() StatementType

StatementType implements the Statement interface.

func (*Set) String

func (n *Set) String() string

func (*Set) WalkStmt

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

WalkStmt is part of the WalkableStmt interface.

type SetDefaultIsolation

type SetDefaultIsolation struct {
	Isolation IsolationLevel
}

SetDefaultIsolation represents a SET SESSION CHARACTERISTICS AS TRANSACTION statement.

func (*SetDefaultIsolation) Format

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

Format implements the NodeFormatter interface.

func (*SetDefaultIsolation) StatementTag

func (*SetDefaultIsolation) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*SetDefaultIsolation) StatementType

func (*SetDefaultIsolation) StatementType() StatementType

StatementType implements the Statement interface.

func (*SetDefaultIsolation) String

func (n *SetDefaultIsolation) String() string

type SetMode

type SetMode int

SetMode is an enum of the various set modes.

const (
	// SetModeAssign represents a SET statement.
	SetModeAssign SetMode = iota

	// SetModeReset represents a RESET statement.
	SetModeReset

	// SetModeClusterSetting represents a SET CLUSTER SETTING statement.
	SetModeClusterSetting
)

type SetTransaction

type SetTransaction struct {
	Modes TransactionModes
}

SetTransaction represents a SET TRANSACTION statement.

func (*SetTransaction) Format

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

Format implements the NodeFormatter interface.

func (*SetTransaction) StatementTag

func (*SetTransaction) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*SetTransaction) StatementType

func (*SetTransaction) StatementType() StatementType

StatementType implements the Statement interface.

func (*SetTransaction) String

func (n *SetTransaction) String() string

type Show

type Show struct {
	Name           string
	ClusterSetting bool
}

Show represents a SHOW statement.

func (*Show) Format

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

Format implements the NodeFormatter interface.

func (*Show) StatementTag

func (*Show) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Show) StatementType

func (*Show) StatementType() StatementType

StatementType implements the Statement interface.

func (*Show) String

func (n *Show) String() string

type ShowBackup

type ShowBackup struct {
	Path Expr
}

ShowBackup represents a SHOW BACKUP statement.

func (*ShowBackup) Format

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

Format implements the NodeFormatter interface.

func (*ShowBackup) StatementTag

func (*ShowBackup) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*ShowBackup) StatementType

func (*ShowBackup) StatementType() StatementType

StatementType implements the Statement interface.

func (*ShowBackup) String

func (n *ShowBackup) String() string

type ShowColumns

type ShowColumns struct {
	Table NormalizableTableName
}

ShowColumns represents a SHOW COLUMNS statement.

func (*ShowColumns) Format

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

Format implements the NodeFormatter interface.

func (*ShowColumns) StatementTag

func (*ShowColumns) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*ShowColumns) StatementType

func (*ShowColumns) StatementType() StatementType

StatementType implements the Statement interface.

func (*ShowColumns) String

func (n *ShowColumns) String() string

type ShowConstraints

type ShowConstraints struct {
	Table NormalizableTableName
}

ShowConstraints represents a SHOW CONSTRAINTS statement.

func (*ShowConstraints) Format

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

Format implements the NodeFormatter interface.

func (*ShowConstraints) StatementTag

func (*ShowConstraints) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*ShowConstraints) StatementType

func (*ShowConstraints) StatementType() StatementType

StatementType implements the Statement interface.

func (*ShowConstraints) String

func (n *ShowConstraints) String() string

type ShowCreateTable

type ShowCreateTable struct {
	Table NormalizableTableName
}

ShowCreateTable represents a SHOW CREATE TABLE statement.

func (*ShowCreateTable) Format

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

Format implements the NodeFormatter interface.

func (*ShowCreateTable) StatementTag

func (*ShowCreateTable) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*ShowCreateTable) StatementType

func (*ShowCreateTable) StatementType() StatementType

StatementType implements the Statement interface.

func (*ShowCreateTable) String

func (n *ShowCreateTable) String() string

type ShowCreateView

type ShowCreateView struct {
	View NormalizableTableName
}

ShowCreateView represents a SHOW CREATE VIEW statement.

func (*ShowCreateView) Format

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

Format implements the NodeFormatter interface.

func (*ShowCreateView) StatementTag

func (*ShowCreateView) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*ShowCreateView) StatementType

func (*ShowCreateView) StatementType() StatementType

StatementType implements the Statement interface.

func (*ShowCreateView) String

func (n *ShowCreateView) String() string

type ShowDatabases

type ShowDatabases struct {
}

ShowDatabases represents a SHOW DATABASES statement.

func (*ShowDatabases) Format

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

Format implements the NodeFormatter interface.

func (*ShowDatabases) StatementTag

func (*ShowDatabases) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*ShowDatabases) StatementType

func (*ShowDatabases) StatementType() StatementType

StatementType implements the Statement interface.

func (*ShowDatabases) String

func (n *ShowDatabases) String() string

type ShowFingerprints

type ShowFingerprints struct {
	Table *NormalizableTableName
	AsOf  AsOfClause
}

ShowFingerprints represents a SHOW EXPERIMENTAL_FINGERPRINTS statement.

func (*ShowFingerprints) Format

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

Format implements the NodeFormatter interface.

func (*ShowFingerprints) StatementTag

func (*ShowFingerprints) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*ShowFingerprints) StatementType

func (*ShowFingerprints) StatementType() StatementType

StatementType implements the Statement interface.

func (*ShowFingerprints) String

func (n *ShowFingerprints) String() string

type ShowGrants

type ShowGrants struct {
	Targets  *TargetList
	Grantees NameList
}

ShowGrants represents a SHOW GRANTS statement. TargetList is defined in grant.go.

func (*ShowGrants) Format

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

Format implements the NodeFormatter interface.

func (*ShowGrants) StatementTag

func (*ShowGrants) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*ShowGrants) StatementType

func (*ShowGrants) StatementType() StatementType

StatementType implements the Statement interface.

func (*ShowGrants) String

func (n *ShowGrants) String() string

type ShowIndex

type ShowIndex struct {
	Table NormalizableTableName
}

ShowIndex represents a SHOW INDEX statement.

func (*ShowIndex) Format

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

Format implements the NodeFormatter interface.

func (*ShowIndex) StatementTag

func (*ShowIndex) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*ShowIndex) StatementType

func (*ShowIndex) StatementType() StatementType

StatementType implements the Statement interface.

func (*ShowIndex) String

func (n *ShowIndex) String() string

type ShowJobs

type ShowJobs struct {
}

ShowJobs represents a SHOW JOBS statement

func (*ShowJobs) Format

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

Format implements the NodeFormatter interface.

func (*ShowJobs) StatementTag

func (*ShowJobs) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*ShowJobs) StatementType

func (*ShowJobs) StatementType() StatementType

StatementType implements the Statement interface.

func (*ShowJobs) String

func (n *ShowJobs) String() string

type ShowQueries

type ShowQueries struct {
	Cluster bool
}

ShowQueries represents a SHOW QUERIES statement

func (*ShowQueries) Format

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

Format implements the NodeFormatter interface.

func (*ShowQueries) StatementTag

func (*ShowQueries) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*ShowQueries) StatementType

func (*ShowQueries) StatementType() StatementType

StatementType implements the Statement interface.

func (*ShowQueries) String

func (n *ShowQueries) String() string

type ShowRanges

type ShowRanges struct {
	Table *NormalizableTableName
	Index *TableNameWithIndex
}

ShowRanges represents a SHOW TESTING_RANGES statement. Only one of Table and Index can be set.

func (*ShowRanges) Format

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

Format implements the NodeFormatter interface.

func (*ShowRanges) StatementTag

func (*ShowRanges) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*ShowRanges) StatementType

func (*ShowRanges) StatementType() StatementType

StatementType implements the Statement interface.

func (*ShowRanges) String

func (n *ShowRanges) String() string

type ShowSessions

type ShowSessions struct {
	Cluster bool
}

ShowSessions represents a SHOW SESSIONS statement

func (*ShowSessions) Format

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

Format implements the NodeFormatter interface.

func (*ShowSessions) StatementTag

func (*ShowSessions) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*ShowSessions) StatementType

func (*ShowSessions) StatementType() StatementType

StatementType implements the Statement interface.

func (*ShowSessions) String

func (n *ShowSessions) String() string

type ShowTables

type ShowTables struct {
	Database Name
}

ShowTables represents a SHOW TABLES statement.

func (*ShowTables) Format

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

Format implements the NodeFormatter interface.

func (*ShowTables) StatementTag

func (*ShowTables) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*ShowTables) StatementType

func (*ShowTables) StatementType() StatementType

StatementType implements the Statement interface.

func (*ShowTables) String

func (n *ShowTables) String() string

type ShowTrace

type ShowTrace struct {
	Statement   Statement
	OnlyKVTrace bool
}

ShowTrace represents a SHOW SESSION TRACE statement.

func (*ShowTrace) Format

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

Format implements the NodeFormatter interface.

func (*ShowTrace) StatementTag

func (*ShowTrace) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*ShowTrace) StatementType

func (*ShowTrace) StatementType() StatementType

StatementType implements the Statement interface.

func (*ShowTrace) String

func (n *ShowTrace) String() string

type ShowTransactionStatus

type ShowTransactionStatus struct {
}

ShowTransactionStatus represents a SHOW TRANSACTION STATUS statement.

func (*ShowTransactionStatus) Format

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

Format implements the NodeFormatter interface.

func (*ShowTransactionStatus) StatementTag

func (*ShowTransactionStatus) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*ShowTransactionStatus) StatementType

func (*ShowTransactionStatus) StatementType() StatementType

StatementType implements the Statement interface.

func (*ShowTransactionStatus) String

func (n *ShowTransactionStatus) String() string

type ShowUsers

type ShowUsers struct {
}

ShowUsers represents a SHOW USERS statement.

func (*ShowUsers) Format

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

Format implements the NodeFormatter interface.

func (*ShowUsers) StatementTag

func (*ShowUsers) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*ShowUsers) StatementType

func (*ShowUsers) StatementType() StatementType

StatementType implements the Statement interface.

func (*ShowUsers) String

func (n *ShowUsers) String() string

type SimpleVisitFn

type SimpleVisitFn func(expr Expr) (err error, recurse bool, newExpr Expr)

SimpleVisitFn is a function that is run for every node in the VisitPre stage; see SimpleVisit.

type Split

type Split struct {
	// Only one of Table and Index can be set.
	Table *NormalizableTableName
	Index *TableNameWithIndex
	// Each row contains values for the columns in the PK or index (or a prefix
	// of the columns).
	Rows *Select
}

Split represents an `ALTER TABLE/INDEX .. SPLIT AT ..` statement.

func (*Split) Format

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

Format implements the NodeFormatter interface.

func (*Split) StatementTag

func (*Split) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Split) StatementType

func (*Split) StatementType() StatementType

StatementType implements the Statement interface.

func (*Split) String

func (n *Split) String() string

type Statement

type Statement interface {
	fmt.Stringer
	NodeFormatter
	StatementType() StatementType
	// StatementTag is a short string identifying the type of statement
	// (usually a single verb). This is different than the Stringer output,
	// which is the actual statement (including args).
	// TODO(dt): Currently tags are always pg-compatible in the future it
	// might make sense to pass a tag format specifier.
	StatementTag() string
}

Statement represents a statement.

func ParseOne

func ParseOne(sql string) (Statement, error)

ParseOne parses a sql statement string, ensuring that it contains only a single statement, and returns that Statement.

func WalkStmt

func WalkStmt(v Visitor, stmt Statement) (newStmt Statement, changed bool)

WalkStmt walks the entire parsed stmt calling WalkExpr on each expression, and replacing each expression with the one returned by WalkExpr.

NOTE: Beware that WalkStmt does not necessarily traverse all parts of a statement by itself. For example, it will not walk into Subquery nodes within a FROM clause or into a JoinCond. Walk's logic is pretty interdependent with the logic for constructing a query plan.

type StatementList

type StatementList []Statement

StatementList is a list of statements.

func Parse

func Parse(sql string) (StatementList, error)

Parse parses a sql statement string and returns a list of Statements.

func (StatementList) Format

func (l StatementList) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (StatementList) String

func (l StatementList) String() string

type StatementSource

type StatementSource struct {
	Statement Statement
}

StatementSource encapsulates one of the other statements as a data source.

func (*StatementSource) Format

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

Format implements the NodeFormatter interface.

type StatementType

type StatementType int

StatementType is the enumerated type for Statement return styles on the wire.

const (
	// Ack indicates that the statement does not have a meaningful
	// return. Examples include SET, BEGIN, COMMIT.
	Ack StatementType = iota
	// DDL indicates that the statement mutates the database schema.
	DDL
	// RowsAffected indicates that the statement returns the count of
	// affected rows.
	RowsAffected
	// Rows indicates that the statement returns the affected rows after
	// the statement was applied.
	Rows
	// CopyIn indicates a COPY FROM statement.
	CopyIn
	// Unknown indicates that the statement does not have a known
	// return style at the time of parsing. This is not first in the
	// enumeration because it is more convenient to have Ack as a zero
	// value, and because the use of Unknown should be an explicit choice.
	// The primary example of this statement type is EXECUTE, where the
	// statement type depends on the statement type of the prepared statement
	// being executed.
	Unknown
)

type StrVal

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

StrVal represents a constant string value.

func (*StrVal) AvailableTypes

func (expr *StrVal) AvailableTypes() []Type

AvailableTypes implements the Constant interface.

To fully take advantage of literal type inference, this method would determine exactly which types are available for a given string. This would entail attempting to parse the literal string as a date, a timestamp, an interval, etc. and having more fine-grained results than strValAvailAllParsable. However, this is not feasible in practice because of the associated parsing overhead.

Conservative approaches like checking the string's length have been investigated to reduce ambiguity and improve type inference in some cases. When doing so, the length of the string literal was compared against all valid date and timestamp formats to quickly gain limited insight into whether parsing the string as the respective datum types could succeed. The hope was to eliminate impossibilities and constrain the returned type sets as much as possible. Unfortunately, two issues were found with this approach:

  • date and timestamp formats do not always imply a fixed-length valid input. For instance, timestamp formats that take fractional seconds can successfully parse inputs of varied length.
  • the set of date and timestamp formats are not disjoint, which means that ambiguity can not be eliminated when inferring the type of string literals that use these shared formats.

While these limitations still permitted improved type inference in many cases, they resulted in behavior that was ultimately incomplete, resulted in unpredictable levels of inference, and occasionally failed to eliminate ambiguity. Further heuristics could have been applied to improve the accuracy of the inference, like checking that all or some characters were digits, but it would not have circumvented the fundamental issues here. Fully parsing the literal into each type would be the only way to concretely avoid the issue of unpredictable inference behavior.

func (*StrVal) Format

func (expr *StrVal) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*StrVal) ResolveAsType

func (expr *StrVal) ResolveAsType(ctx *SemaContext, typ Type) (Datum, error)

ResolveAsType implements the Constant interface.

func (*StrVal) String

func (node *StrVal) String() string

func (*StrVal) TypeCheck

func (expr *StrVal) TypeCheck(ctx *SemaContext, desired Type) (TypedExpr, error)

TypeCheck implements the Expr interface.

func (*StrVal) Walk

func (expr *StrVal) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type StringColType

type StringColType struct {
	Name string
	N    int
}

StringColType represents a STRING, CHAR or VARCHAR type.

func (*StringColType) Format

func (node *StringColType) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*StringColType) String

func (node *StringColType) String() string

type Subquery

type Subquery struct {
	Select SelectStatement
}

Subquery represents a subquery.

func (*Subquery) Format

func (node *Subquery) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*Subquery) String

func (node *Subquery) String() string

func (*Subquery) TypeCheck

func (expr *Subquery) TypeCheck(_ *SemaContext, desired Type) (TypedExpr, error)

TypeCheck implements the Expr interface.

func (*Subquery) Variable

func (*Subquery) Variable()

Variable implements the VariableExpr interface.

func (*Subquery) Walk

func (expr *Subquery) Walk(v Visitor) Expr

Walk implements the Expr interface.

type TArray

type TArray struct{ Typ Type }

TArray is the type of a DArray.

func (TArray) Equivalent

func (a TArray) Equivalent(other Type) bool

Equivalent implements the Type interface.

func (TArray) FamilyEqual

func (TArray) FamilyEqual(other Type) bool

FamilyEqual implements the Type interface.

func (TArray) IsAmbiguous

func (a TArray) IsAmbiguous() bool

IsAmbiguous implements the Type interface.

func (TArray) Oid

func (a TArray) Oid() oid.Oid

Oid implements the Type interface.

func (TArray) SQLName

func (a TArray) SQLName() string

SQLName implements the Type interface.

func (TArray) Size

func (TArray) Size() (uintptr, bool)

Size implements the Type interface.

func (TArray) String

func (a TArray) String() string

type TCollatedString

type TCollatedString struct {
	Locale string
}

TCollatedString is the type of strings with a locale.

func (TCollatedString) Equivalent

func (t TCollatedString) Equivalent(other Type) bool

Equivalent implements the Type interface.

func (TCollatedString) FamilyEqual

func (TCollatedString) FamilyEqual(other Type) bool

FamilyEqual implements the Type interface.

func (TCollatedString) IsAmbiguous

func (t TCollatedString) IsAmbiguous() bool

IsAmbiguous implements the Type interface.

func (TCollatedString) Oid

func (TCollatedString) Oid() oid.Oid

Oid implements the Type interface.

func (TCollatedString) SQLName

func (TCollatedString) SQLName() string

SQLName implements the Type interface.

func (TCollatedString) Size

func (TCollatedString) Size() (uintptr, bool)

Size implements the Type interface.

func (TCollatedString) String

func (t TCollatedString) String() string

String implements the fmt.Stringer interface.

type TPlaceholder

type TPlaceholder struct {
	Name string
}

TPlaceholder is the type of a placeholder.

func (TPlaceholder) Equivalent

func (t TPlaceholder) Equivalent(other Type) bool

Equivalent implements the Type interface.

func (TPlaceholder) FamilyEqual

func (TPlaceholder) FamilyEqual(other Type) bool

FamilyEqual implements the Type interface.

func (TPlaceholder) IsAmbiguous

func (TPlaceholder) IsAmbiguous() bool

IsAmbiguous implements the Type interface.

func (TPlaceholder) Oid

func (TPlaceholder) Oid() oid.Oid

Oid implements the Type interface.

func (TPlaceholder) SQLName

func (TPlaceholder) SQLName() string

SQLName implements the Type interface.

func (TPlaceholder) Size

func (TPlaceholder) Size() (uintptr, bool)

Size implements the Type interface.

func (TPlaceholder) String

func (t TPlaceholder) String() string

String implements the fmt.Stringer interface.

type TTable

type TTable struct{ Cols TTuple }

TTable is the type of a DTable. See the comments at the start of generator_builtins.go for details.

func (TTable) Equivalent

func (a TTable) Equivalent(other Type) bool

Equivalent implements the Type interface.

func (TTable) FamilyEqual

func (TTable) FamilyEqual(other Type) bool

FamilyEqual implements the Type interface.

func (TTable) IsAmbiguous

func (a TTable) IsAmbiguous() bool

IsAmbiguous implements the Type interface.

func (TTable) Oid

func (TTable) Oid() oid.Oid

Oid implements the Type interface.

func (TTable) SQLName

func (TTable) SQLName() string

SQLName implements the Type interface.

func (TTable) Size

func (a TTable) Size() (uintptr, bool)

Size implements the Type interface.

func (TTable) String

func (a TTable) String() string

type TTuple

type TTuple []Type

TTuple is the type of a DTuple.

func (TTuple) Equivalent

func (t TTuple) Equivalent(other Type) bool

Equivalent implements the Type interface.

func (TTuple) FamilyEqual

func (TTuple) FamilyEqual(other Type) bool

FamilyEqual implements the Type interface.

func (TTuple) IsAmbiguous

func (t TTuple) IsAmbiguous() bool

IsAmbiguous implements the Type interface.

func (TTuple) Oid

func (TTuple) Oid() oid.Oid

Oid implements the Type interface.

func (TTuple) SQLName

func (TTuple) SQLName() string

SQLName implements the Type interface.

func (TTuple) Size

func (t TTuple) Size() (uintptr, bool)

Size implements the Type interface.

func (TTuple) String

func (t TTuple) String() string

String implements the fmt.Stringer interface.

type TableDef

type TableDef interface {
	NodeFormatter
	// contains filtered or unexported methods
}

TableDef represents a column, index or constraint definition within a CREATE TABLE statement.

type TableDefs

type TableDefs []TableDef

TableDefs represents a list of table definitions.

func (TableDefs) Format

func (node TableDefs) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type TableExpr

type TableExpr interface {
	NodeFormatter
	// contains filtered or unexported methods
}

TableExpr represents a table expression.

type TableExprs

type TableExprs []TableExpr

TableExprs represents a list of table expressions.

func (TableExprs) Format

func (node TableExprs) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type TableName

type TableName struct {
	PrefixName   Name
	DatabaseName Name
	TableName    Name

	// DBNameOriginallyOmitted, when set to true, causes the
	// String()/Format() methods to omit the database name even if one
	// is set. This is used to ensure that pretty-printing
	// a TableName normalized from a parser input yields back
	// the original syntax.
	DBNameOriginallyOmitted bool

	// PrefixOriginallySpecified indicates whether a prefix was
	// explicitly indicated in the input syntax.
	PrefixOriginallySpecified bool
}

TableName corresponds to the name of a table in a FROM clause, INSERT or UPDATE statement (and possibly other places).

func ParseTableName

func ParseTableName(sql string) (*TableName, error)

ParseTableName parses a table name.

func (*TableName) Database

func (t *TableName) Database() string

Database retrieves the unqualified database name.

func (*TableName) Format

func (t *TableName) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*TableName) NormalizeTableName

func (t *TableName) NormalizeTableName() (*TableName, error)

NormalizeTableName implements the TableNameReference interface.

func (*TableName) NormalizeTablePattern

func (t *TableName) NormalizeTablePattern() (TablePattern, error)

NormalizeTablePattern implements the TablePattern interface.

func (*TableName) NormalizedTableName

func (t *TableName) NormalizedTableName() TableName

NormalizedTableName normalize DatabaseName and TableName to lowercase and performs Unicode Normalization.

func (*TableName) QualifyWithDatabase

func (t *TableName) QualifyWithDatabase(database string) error

QualifyWithDatabase adds an indirection for the database, if it's missing. It transforms: table -> database.table table@index -> database.table@index

func (*TableName) String

func (t *TableName) String() string

func (*TableName) Table

func (t *TableName) Table() string

Table retrieves the unqualified table name.

type TableNameReference

type TableNameReference interface {
	fmt.Stringer
	NodeFormatter
	NormalizeTableName() (*TableName, error)
}

TableNameReference implements the editable cell of a TableExpr that refers to a single table.

type TableNameReferences

type TableNameReferences []TableNameReference

TableNameReferences corresponds to a comma-delimited list of table name references.

func (TableNameReferences) Format

func (t TableNameReferences) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type TableNameWithIndex

type TableNameWithIndex struct {
	Table NormalizableTableName
	Index Name

	// SearchTable indicates that we have just an index (no table name); we will
	// need to search for a table that has an index with the given name.
	//
	// To allow schema-qualified index names in this case, the index is actually
	// specified in Table as the table name, and Index is empty.
	SearchTable bool
}

TableNameWithIndex represents a "table@index", used in statements that specifically refer to an index.

func (TableNameWithIndex) Format

func (n TableNameWithIndex) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type TableNameWithIndexList

type TableNameWithIndexList []*TableNameWithIndex

TableNameWithIndexList is a list of indexes.

func (TableNameWithIndexList) Format

func (n TableNameWithIndexList) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type TableNames

type TableNames []TableName

TableNames represents a comma separated list (see the Format method) of table names.

func (TableNames) Format

func (ts TableNames) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (TableNames) String

func (ts TableNames) String() string

type TablePattern

type TablePattern interface {
	fmt.Stringer
	NodeFormatter

	NormalizeTablePattern() (TablePattern, error)
}

TablePattern is the common interface to UnresolvedName, TableName and AllTablesSelector.

type TablePatterns

type TablePatterns []TablePattern

TablePatterns implement a comma-separated list of table patterns. Used by e.g. the GRANT statement.

func (TablePatterns) Format

func (tt TablePatterns) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type TableRef

type TableRef struct {
	// TableID is the descriptor ID of the requested table.
	TableID int64

	// ColumnIDs is the list of column IDs requested in the table.
	// Note that a nil array here means "unspecified" (all columns)
	// whereas an array of length 0 means "zero columns".
	Columns []ColumnID
}

TableRef represents a numeric table reference. (Syntax !NNN in SQL.)

func (*TableRef) Format

func (n *TableRef) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*TableRef) String

func (n *TableRef) String() string

type TargetList

type TargetList struct {
	Databases NameList
	Tables    TablePatterns
}

TargetList represents a list of targets. Only one field may be non-nil.

func (TargetList) Format

func (tl TargetList) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type TestingRelocate

type TestingRelocate struct {
	// Only one of Table and Index can be set.
	Table *NormalizableTableName
	Index *TableNameWithIndex
	// Each row contains an array with store ids and values for the columns in the
	// PK or index (or a prefix of the columns).
	// See docs/RFCS/sql_split_syntax.md.
	Rows *Select
}

TestingRelocate represents an `ALTER TABLE/INDEX .. TESTING_RELOCATE ..` statement.

func (*TestingRelocate) Format

func (node *TestingRelocate) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*TestingRelocate) StatementTag

func (*TestingRelocate) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*TestingRelocate) StatementType

func (*TestingRelocate) StatementType() StatementType

StatementType implements the Statement interface.

func (*TestingRelocate) String

func (n *TestingRelocate) String() string

type TimestampColType

type TimestampColType struct {
}

TimestampColType represents a TIMESTAMP type.

func (*TimestampColType) Format

func (node *TimestampColType) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*TimestampColType) String

func (node *TimestampColType) String() string

type TimestampTZColType

type TimestampTZColType struct {
}

TimestampTZColType represents a TIMESTAMP type.

func (*TimestampTZColType) Format

func (node *TimestampTZColType) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*TimestampTZColType) String

func (node *TimestampTZColType) String() string

type TransactionModes

type TransactionModes struct {
	Isolation     IsolationLevel
	UserPriority  UserPriority
	ReadWriteMode ReadWriteMode
}

TransactionModes holds the transaction modes for a transaction.

func (*TransactionModes) Format

func (node *TransactionModes) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type Truncate

type Truncate struct {
	Tables       TableNameReferences
	DropBehavior DropBehavior
}

Truncate represents a TRUNCATE statement.

func (*Truncate) Format

func (node *Truncate) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*Truncate) StatementTag

func (*Truncate) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Truncate) StatementType

func (*Truncate) StatementType() StatementType

StatementType implements the Statement interface.

func (*Truncate) String

func (n *Truncate) String() string

type Tuple

type Tuple struct {
	Exprs Exprs
	// contains filtered or unexported fields
}

Tuple represents a parenthesized list of expressions.

func (*Tuple) Eval

func (t *Tuple) Eval(ctx *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*Tuple) Format

func (node *Tuple) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*Tuple) ResolvedType

func (node *Tuple) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (*Tuple) String

func (node *Tuple) String() string

func (*Tuple) TypeCheck

func (expr *Tuple) TypeCheck(ctx *SemaContext, desired Type) (TypedExpr, error)

TypeCheck implements the Expr interface.

func (*Tuple) Walk

func (expr *Tuple) Walk(v Visitor) Expr

Walk implements the Expr interface.

type Type

type Type interface {
	fmt.Stringer
	// Equivalent returns whether the receiver and the other type are equivalent.
	// We say that two type patterns are "equivalent" when they are structurally
	// equivalent given that a wildcard is equivalent to any type. When neither
	// Type is ambiguous (see IsAmbiguous), equivalency is the same as type equality.
	Equivalent(other Type) bool
	// FamilyEqual returns whether the receiver and the other type have the same
	// constructor.
	FamilyEqual(other Type) bool

	// Oid returns the type's Postgres object ID.
	Oid() oid.Oid
	// SQLName returns the type's SQL standard name. This can be looked up for a
	// type `t` in postgres by running `SELECT format_type(t::regtype, NULL)`.
	SQLName() string

	// Size returns a lower bound on the total size of a Datum whose type is the
	// receiver in bytes, including memory that is pointed at (even if shared
	// between Datum instances) but excluding allocation overhead.
	//
	// The second argument indicates whether data of this type have different
	// sizes.
	//
	// It holds for every Datum d that d.Size() >= d.ResolvedType().Size().
	Size() (uintptr, bool)

	// IsAmbiguous returns whether the type is ambiguous or fully defined. This
	// is important for parameterized types to determine whether they are fully
	// concrete type specification or not.
	IsAmbiguous() bool
}

Type represents a SQL type.

func CastTargetToDatumType

func CastTargetToDatumType(t CastTargetType) Type

CastTargetToDatumType produces a Type equivalent to the given SQL cast target type.

func UnwrapType

func UnwrapType(t Type) Type

UnwrapType returns the base Type type for a provided type, stripping a *TOidWrapper if present. This is useful for cases like type switches, where type aliases should be ignored.

type TypedExpr

type TypedExpr interface {
	Expr
	// Eval evaluates an SQL expression. Expression evaluation is a
	// mostly straightforward walk over the parse tree. The only
	// significant complexity is the handling of types and implicit
	// conversions. See binOps and cmpOps for more details. Note that
	// expression evaluation returns an error if certain node types are
	// encountered: Placeholder, VarName (and related UnqualifiedStar,
	// UnresolvedName and AllColumnsSelector) or Subquery. These nodes
	// should be replaced prior to expression evaluation by an
	// appropriate WalkExpr. For example, Placeholder should be replace
	// by the argument passed from the client.
	Eval(*EvalContext) (Datum, error)
	// ResolvedType provides the type of the TypedExpr, which is the type of Datum
	// that the TypedExpr will return when evaluated.
	ResolvedType() Type
}

TypedExpr represents a well-typed expression.

func ReType

func ReType(expr TypedExpr, wantedType Type) (TypedExpr, error)

ReType ensures that the given numeric expression evaluates to the requested type, inserting a cast if necessary.

func TypeCheck

func TypeCheck(expr Expr, ctx *SemaContext, desired Type) (TypedExpr, error)

TypeCheck performs type checking on the provided expression tree, returning the new typed expression tree, which additionally permits evaluation and type introspection globally and on each sub-tree.

While doing so, it will fold numeric constants and bind placeholder names to their inferred types in the provided context. The optional desired parameter can be used to hint the desired type for the root of the resulting typed expression tree. Like with Expr.TypeCheck, it is not valid to provide a nil desired type. Instead, call it with the wildcard type TypeAny if no specific type is desired.

func TypeCheckAndRequire

func TypeCheckAndRequire(expr Expr, ctx *SemaContext, required Type, op string) (TypedExpr, error)

TypeCheckAndRequire performs type checking on the provided expression tree in an identical manner to TypeCheck. It then asserts that the resulting TypedExpr has the provided return type, returning both the typed expression and an error if it does not.

type TypedExprs

type TypedExprs []TypedExpr

TypedExprs represents a list of well-typed value expressions. It's not a valid expression because it's not parenthesized.

func (TypedExprs) String

func (node TypedExprs) String() string

type UUIDColType

type UUIDColType struct {
}

UUIDColType represents a UUID type.

func (*UUIDColType) Format

func (node *UUIDColType) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*UUIDColType) String

func (node *UUIDColType) String() string

type UnaryExpr

type UnaryExpr struct {
	Operator UnaryOperator
	Expr     Expr
	// contains filtered or unexported fields
}

UnaryExpr represents a unary value expression.

func (*UnaryExpr) Eval

func (expr *UnaryExpr) Eval(ctx *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (*UnaryExpr) Format

func (node *UnaryExpr) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (UnaryExpr) ResolvedType

func (ta UnaryExpr) ResolvedType() Type

func (*UnaryExpr) String

func (node *UnaryExpr) String() string

func (*UnaryExpr) TypeCheck

func (expr *UnaryExpr) TypeCheck(ctx *SemaContext, desired Type) (TypedExpr, error)

TypeCheck implements the Expr interface.

func (*UnaryExpr) TypedInnerExpr

func (node *UnaryExpr) TypedInnerExpr() TypedExpr

TypedInnerExpr returns the UnaryExpr's inner expression as a TypedExpr.

func (*UnaryExpr) Walk

func (expr *UnaryExpr) Walk(v Visitor) Expr

Walk implements the Expr interface.

type UnaryOp

type UnaryOp struct {
	Typ        Type
	ReturnType Type
	// contains filtered or unexported fields
}

UnaryOp is a unary operator.

type UnaryOperator

type UnaryOperator int

UnaryOperator represents a unary operator.

const (
	UnaryPlus UnaryOperator = iota
	UnaryMinus
	UnaryComplement
)

UnaryExpr.Operator

func (UnaryOperator) String

func (i UnaryOperator) String() string

type UnionClause

type UnionClause struct {
	Type        UnionType
	Left, Right *Select
	All         bool
}

UnionClause represents a UNION statement.

func (*UnionClause) Format

func (node *UnionClause) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*UnionClause) StatementTag

func (*UnionClause) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*UnionClause) StatementType

func (*UnionClause) StatementType() StatementType

StatementType implements the Statement interface.

func (*UnionClause) String

func (n *UnionClause) String() string

type UnionType

type UnionType int

UnionType represents one of the three set operations in sql.

const (
	UnionOp UnionType = iota
	IntersectOp
	ExceptOp
)

Union.Type

func (UnionType) String

func (i UnionType) String() string

type UniqueConstraint

type UniqueConstraint struct{}

UniqueConstraint represents UNIQUE on a column.

type UniqueConstraintTableDef

type UniqueConstraintTableDef struct {
	IndexTableDef
	PrimaryKey bool
}

UniqueConstraintTableDef represents a unique constraint within a CREATE TABLE statement.

func (*UniqueConstraintTableDef) Format

func (node *UniqueConstraintTableDef) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type UnqualifiedStar

type UnqualifiedStar struct{}

UnqualifiedStar corresponds to a standalone '*' in an expression or a '*' as name part of an UnresolvedName.

func (UnqualifiedStar) Eval

func (expr UnqualifiedStar) Eval(ctx *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (UnqualifiedStar) Format

func (UnqualifiedStar) Format(buf *bytes.Buffer, _ FmtFlags)

Format implements the NodeFormatter interface.

func (UnqualifiedStar) NormalizeVarName

func (u UnqualifiedStar) NormalizeVarName() (VarName, error)

NormalizeVarName is a no-op for UnqualifiedStar (already normalized)

func (UnqualifiedStar) ResolvedType

func (UnqualifiedStar) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (UnqualifiedStar) String

func (u UnqualifiedStar) String() string

func (UnqualifiedStar) TypeCheck

func (expr UnqualifiedStar) TypeCheck(_ *SemaContext, desired Type) (TypedExpr, error)

TypeCheck implements the Expr interface.

func (UnqualifiedStar) Variable

func (UnqualifiedStar) Variable()

Variable implements the VariableExpr interface.

func (UnqualifiedStar) Walk

func (expr UnqualifiedStar) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type UnresolvedName

type UnresolvedName NameParts

UnresolvedName holds the initial syntax of a name as determined during parsing.

func (UnresolvedName) Eval

func (expr UnresolvedName) Eval(ctx *EvalContext) (Datum, error)

Eval implements the TypedExpr interface.

func (UnresolvedName) Format

func (u UnresolvedName) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (UnresolvedName) NormalizeTableName

func (n UnresolvedName) NormalizeTableName() (*TableName, error)

NormalizeTableName implements the TableNameReference interface.

func (UnresolvedName) NormalizeTablePattern

func (n UnresolvedName) NormalizeTablePattern() (TablePattern, error)

NormalizeTablePattern resolves an UnresolvedName to either a TableName or AllTablesSelector.

func (UnresolvedName) NormalizeUnqualifiedColumnItem

func (n UnresolvedName) NormalizeUnqualifiedColumnItem() (*ColumnItem, error)

NormalizeUnqualifiedColumnItem normalizes a UnresolvedName for all the forms it can have inside a context that requires an unqualified column item (e.g. UPDATE LHS, INSERT, etc.).

func (UnresolvedName) NormalizeVarName

func (n UnresolvedName) NormalizeVarName() (VarName, error)

NormalizeVarName normalizes a UnresolvedName for all the forms it can have inside an expression context.

func (UnresolvedName) ResolveFunction

func (n UnresolvedName) ResolveFunction(searchPath SearchPath) (*FunctionDefinition, error)

ResolveFunction transforms an UnresolvedName to a FunctionDefinition.

func (UnresolvedName) ResolvedType

func (UnresolvedName) ResolvedType() Type

ResolvedType implements the TypedExpr interface.

func (UnresolvedName) String

func (u UnresolvedName) String() string

func (UnresolvedName) TypeCheck

func (expr UnresolvedName) TypeCheck(s *SemaContext, desired Type) (TypedExpr, error)

TypeCheck implements the Expr interface.

func (UnresolvedName) Variable

func (UnresolvedName) Variable()

Variable implements the VariableExpr interface. Although, the UnresolvedName ought to be replaced to an IndexedVar before the points the VariableExpr interface is used.

func (UnresolvedName) Walk

func (expr UnresolvedName) Walk(_ Visitor) Expr

Walk implements the Expr interface.

type UnresolvedNames

type UnresolvedNames []UnresolvedName

UnresolvedNames corresponds to a comma-separate list of unresolved names. Note: this should be treated as immutable when embedded in an Expr context, otherwise the Walk code must be updated to duplicate the array an Expr node is duplicated.

func (UnresolvedNames) Format

func (u UnresolvedNames) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type Update

type Update struct {
	Table     TableExpr
	Exprs     UpdateExprs
	Where     *Where
	Returning ReturningClause
}

Update represents an UPDATE statement.

func (*Update) CopyNode

func (stmt *Update) CopyNode() *Update

CopyNode makes a copy of this Statement without recursing in any child Statements.

func (*Update) Format

func (node *Update) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (*Update) StatementTag

func (*Update) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (*Update) StatementType

func (n *Update) StatementType() StatementType

StatementType implements the Statement interface.

func (*Update) String

func (n *Update) String() string

func (*Update) WalkStmt

func (stmt *Update) WalkStmt(v Visitor) Statement

WalkStmt is part of the WalkableStmt interface.

type UpdateExpr

type UpdateExpr struct {
	Tuple bool
	Names UnresolvedNames
	Expr  Expr
}

UpdateExpr represents an update expression.

func (*UpdateExpr) Format

func (node *UpdateExpr) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type UpdateExprs

type UpdateExprs []*UpdateExpr

UpdateExprs represents a list of update expressions.

func (UpdateExprs) Format

func (node UpdateExprs) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type UserPriority

type UserPriority int

UserPriority holds the user priority for a transaction.

const (
	UnspecifiedUserPriority UserPriority = iota
	Low
	Normal
	High
)

UserPriority values

func (UserPriority) String

func (up UserPriority) String() string

type UsingJoinCond

type UsingJoinCond struct {
	Cols NameList
}

UsingJoinCond represents a USING join condition.

func (*UsingJoinCond) Format

func (node *UsingJoinCond) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type ValidationBehavior

type ValidationBehavior int

ValidationBehavior specifies whether or not a constraint is validated.

const (
	// ValidationDefault is the default validation behavior (immediate).
	ValidationDefault ValidationBehavior = iota
	// ValidationSkip skips validation of any existing data.
	ValidationSkip
)

type ValueGenerator

type ValueGenerator interface {
	// ColumnTypes returns the type signature of this value generator.
	// Used by DTable.ResolvedType().
	ColumnTypes() TTuple

	// Start initializes the generator. Must be called once before
	// Next() and Values().
	Start() error

	// Next determines whether there is a row of data available.
	Next() (bool, error)

	// Values retrieves the current row of data.
	Values() Datums

	// Close must be called after Start() before disposing of the
	// ValueGenerator. It does not need to be called if Start() has not
	// been called yet.
	Close()
}

ValueGenerator is the interface provided by the object held by a DTable; objects that implement this interface are able to produce rows of values in a streaming fashion (like Go iterators or generators in Python).

type ValuesClause

type ValuesClause struct {
	Tuples []*Tuple
}

ValuesClause represents a VALUES clause.

func (*ValuesClause) Format

func (node *ValuesClause) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

func (ValuesClause) StatementTag

func (ValuesClause) StatementTag() string

StatementTag returns a short string identifying the type of statement.

func (ValuesClause) StatementType

func (ValuesClause) StatementType() StatementType

StatementType implements the Statement interface.

func (*ValuesClause) String

func (n *ValuesClause) String() string

func (*ValuesClause) WalkStmt

func (stmt *ValuesClause) WalkStmt(v Visitor) Statement

WalkStmt is part of the WalkableStmt interface.

type VarName

type VarName interface {
	TypedExpr

	NormalizeVarName() (VarName, error)
}

VarName is the common interface to UnresolvedName, ColumnItem and AllColumnsSelector for use in expression contexts.

func StarExpr

func StarExpr() VarName

StarExpr is a convenience function that represents an unqualified "*".

type VariableExpr

type VariableExpr interface {
	Expr
	Variable()
}

VariableExpr is an Expr that may change per row. It is used to signal the evaluation/simplification machinery that the underlying Expr is not constant.

type VariadicType

type VariadicType struct {
	Typ Type
}

VariadicType is a typeList implementation which accepts any number of arguments and matches when each argument is either NULL or of the type typ.

func (VariadicType) Length

func (v VariadicType) Length() int

Length implements the typeList interface.

func (VariadicType) String

func (v VariadicType) String() string

func (VariadicType) Types

func (v VariadicType) Types() []Type

Types implements the typeList interface.

type VectorColType

type VectorColType struct {
	Name      string
	ParamType ColumnType
}

VectorColType is the base for VECTOR column types, which are Postgres's older, limited version of ARRAYs. These are not meant to be persisted, because ARRAYs are a strict superset.

func (*VectorColType) Format

func (node *VectorColType) Format(buf *bytes.Buffer, _ FmtFlags)

Format implements the NodeFormatter interface.

func (*VectorColType) String

func (node *VectorColType) String() string

type Visitor

type Visitor interface {
	// VisitPre is called for each node before recursing into that subtree. Upon return, if recurse
	// is false, the visit will not recurse into the subtree (and VisitPost will not be called for
	// this node).
	//
	// The returned Expr replaces the visited expression and can be used for rewriting expressions.
	// The function should NOT modify nodes in-place; it should make copies of nodes. The Walk
	// infrastructure will automatically make copies of parents as needed.
	VisitPre(expr Expr) (recurse bool, newExpr Expr)

	// VisitPost is called for each node after recursing into the subtree. The returned Expr
	// replaces the visited expression and can be used for rewriting expressions.
	//
	// The returned Expr replaces the visited expression and can be used for rewriting expressions.
	// The function should NOT modify nodes in-place; it should make and return copies of nodes. The
	// Walk infrastructure will automatically make copies of parents as needed.
	VisitPost(expr Expr) (newNode Expr)
}

Visitor defines methods that are called for nodes during an expression or statement walk.

type WalkableStmt

type WalkableStmt interface {
	Statement
	WalkStmt(Visitor) Statement
}

WalkableStmt is implemented by statements that can appear inside an expression (selects) or we want to start a walk from (using WalkStmt).

type When

type When struct {
	Cond Expr
	Val  Expr
}

When represents a WHEN sub-expression.

func (*When) Format

func (node *When) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type Where

type Where struct {
	Type string
	Expr Expr
}

Where represents a WHERE or HAVING clause.

func (*Where) Format

func (node *Where) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type Window

type Window []*WindowDef

Window represents a WINDOW clause.

func (Window) Format

func (node Window) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type WindowDef

type WindowDef struct {
	Name       Name
	RefName    Name
	Partitions Exprs
	OrderBy    OrderBy
}

WindowDef represents a single window definition expression.

func (*WindowDef) Format

func (node *WindowDef) Format(buf *bytes.Buffer, f FmtFlags)

Format implements the NodeFormatter interface.

type WindowFrame

type WindowFrame struct {
	// constant for all calls to WindowFunc.Add
	Rows        []IndexedRow
	ArgIdxStart int // the index which arguments to the window function begin
	ArgCount    int // the number of window function arguments

	// changes for each row (each call to WindowFunc.Add)
	RowIdx int // the current row index

	// changes for each peer group
	FirstPeerIdx int // the first index in the current peer group
	PeerRowCount int // the number of rows in the current peer group
}

WindowFrame is a view into a subset of data over which calculations are made.

type WindowFunc

type WindowFunc interface {
	// Compute computes the window function for the provided window frame, given the
	// current state of WindowFunc. The method should be called sequentially for every
	// row in a partition in turn with the desired ordering of the WindowFunc. This is
	// because there is an implicit carried dependency between each row and all those
	// that have come before it (like in an AggregateFunc). As such, this approach does
	// not present any exploitable associativity/commutativity for optimization.
	Compute(context.Context, *EvalContext, WindowFrame) (Datum, error)

	// Close allows the window function to free any memory it requested during execution,
	// such as during the execution of an aggregation like CONCAT_AGG or ARRAY_AGG.
	Close(context.Context, *EvalContext)
}

WindowFunc performs a computation on each row using data from a provided WindowFrame.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL