package
1.1.0-rc.1
Repository: https://github.com/soopsio/cockroach.git
Documentation: pkg.go.dev

# README

Embedded help texts

We equip the generated parser with the ability to report contextual help in two circumstances:

  • when the user explicitly requests help with the HELPTOKEN (current syntax: standalone "?")
  • when the user makes a grammatical mistake (e.g. INSERT sometable INTO(x, y) ...)

Help texts embedded in the grammar

The help is embedded in the grammar using special markers in yacc comments, for example:

// %Help: HELPKEY - shortdescription
// %Category: SomeCat
// %Text: whatever until next %marker at start of line, or non-comment.
// %SeeAlso: whatever until next %marker at start of line, or non-comment.
// %End (optional)

The "HELPKEY" becomes the map key in the generated Go map.

These texts are extracted automatically by help.awk and converted into a Go data structure in help_messages.go.

Support in the parser

Primary mechanism - LALR error recovery

The primary mechanism is leveraging error recovery in LALR parsers using the special error token [1] [2]: when an unexpected token is encountered, the LALR parser will pop tokens on the stack until the prefix matches a grammar rule with the special "error" token (if any). If such a rule exists, its action is used to reduce and the erroneous tokens are discarded.

This mechanism is used both when the user makes a mistake, and when the user inserts the HELPTOKEN in the middle of a statement. When present in the middle of a statement, HELPTOKEN is considered an error and triggers the error recovery.

We use this for contextual help by providing error rules that generate a contextual help text during LALR error recovery.

For example:

backup_stmt:
  BACKUP targets TO string_or_placeholder opt_as_of_clause opt_incremental opt_with_options
  {
    $$.val = &Backup{Targets: $2.targetList(), To: $4.expr(), IncrementalFrom: $6.exprs(), AsOf: $5.asOfClause(), Options: $7.kvOptions()}
  }
| BACKUP error { return helpWith(sqllex, `BACKUP`) }

In this example, the grammar specifies that if the BACKUP keyword is followed by some input tokens such that the first (valid) grammar rule doesn't apply, the parser will "recover from the error" by backtracking up until the point it only sees BACKUP on the stack followed by non-parsable tokens, at which points it takes the error rule and executes its action.

The action is return helpWith(...). What this does is:

  • halts parsing (the generated parser executes all actions in a big loop; a return interrupts this loop);
  • makes the parser return with an error (the helpWith function returns non-zero);
  • extends the parsing error message with a help text; this help text can subsequently be exploited in a client to display the help message in a friendly manner.

Code generation

Since the pattern "{ return helpWith(sqllex, ...) }" is common, we also implement a shorthand syntax based on comments, for example:

backup_stmt:
   ...
| BACKUP error // SHOW HELP: BACKUP

The special comment syntax "SHOW HELP: XXXX" is substituted by means of an auxiliary script (replace_help_rules.awk) into the form explained above.

Secondary mechanism - explicit help token

The mechanism described above works both when the user make a grammatical error and when they place the HELPTOKEN in the middle of a statement, rendering it invalid.

However for contextual help this is not sufficient: what happens if the user requests HELPTOKEN at a position in the grammar where everything before is a complete, valid SQL input?

For example: DELETE FROM foo ?

When encountering this input, the LALR parser will see DELETE FROM foo first, then reduce using the DELETE action because everything up to this point is a valid DELETE statement. When the HELPTOKEN is encountered, the statement has already been completed and the LALR parser doesn't 'know' any more that it was in the context of a DELETE statement.

If we try to place an error-based recovery rule at the top-level:

stmt:
  alter_stmt
| backup_stmt
| ...
| delete_stmt
| ...
| error { ??? }

This wouldn't work: the code inside the error action cannot "observe" the tokens observed so far and there would be no way to know whether the error should be about DELETE, or instead about ALTER, BACKUP, etc.

So in order to handle HELPTOKEN after a valid statement, we must place it in a rule where the context is still available, that is before the statement's grammar rule is reduced.

Where would that be? Suppose we had a simple statement rule:

somesimplestmt:
  SIMPLE DO SOMETHING { $$ = reduce(...) }
| SIMPLE error { help ... }

We could extend with:

somesimplestmt:
  SIMPLE DO SOMETHING { $$ = reduce(...) }
| SIMPLE DO SOMETHING HELPTOKEN { help ... }
| SIMPLE error { help ... }

(the alternative also works:

somesimplestmt:
  SIMPLE DO SOMETHING { $$ = reduce(...) }
| SIMPLE DO SOMETHING error { help ... }
| SIMPLE error { help ... }

)

That is all fine and dandy, but in SQL we have statements with many alternate forms, for example:

alter_rename_table_stmt:
  ALTER TABLE relation_expr RENAME TO qualified_name { ... }
| ALTER TABLE IF EXISTS relation_expr RENAME TO qualified_name { ... }
| ALTER TABLE relation_expr RENAME opt_column name TO name { ... }
| ALTER TABLE IF EXISTS relation_expr RENAME opt_column name TO name { ... }

To add complementary handling of the help token at the end of valid statements we could, but would hate to, duplicate all the rules:

alter_rename_table_stmt:
  ALTER TABLE relation_expr RENAME TO qualified_name { ... }
| ALTER TABLE relation_expr RENAME TO qualified_name HELPTOKEN { help ... }
| ALTER TABLE IF EXISTS relation_expr RENAME TO qualified_name { ... }
| ALTER TABLE IF EXISTS relation_expr RENAME TO qualified_name HELPTOKEN { help ... }
| ALTER TABLE relation_expr RENAME opt_column name TO name { ... }
| ALTER TABLE relation_expr RENAME opt_column name TO name HELPTOKEN { help ... }
| ALTER TABLE IF EXISTS relation_expr RENAME opt_column name TO name { ... }
| ALTER TABLE IF EXISTS relation_expr RENAME opt_column name TO name HELPTOKEN { help ... }

This duplication is horrendous (not to mention hard to maintain), so instead we should attempt to factor the help token in a context where it is still known that we are dealing just with that statement.

The following works:

alter_rename_table_stmt:
  real_alter_rename_table_stmt { $$ = $1 }
| real_alter_rename_table_stmt HELPTOKEN { help ... }

real_alter_rename_table_stmt:
  ALTER TABLE relation_expr RENAME TO qualified_name { ... }
| ALTER TABLE IF EXISTS relation_expr RENAME TO qualified_name { ... }
| ALTER TABLE relation_expr RENAME opt_column name TO name { ... }
| ALTER TABLE IF EXISTS relation_expr RENAME opt_column name TO name { ... }

Or does it? Without anything else, yacc complains with a "shift/reduce conflict". The reason is coming from the ambiguity: when the parsing stack contains everything sufficient to match a real_alter_rename_table_stmt, there is a choice between reducing the simple form alter_rename_table_stmt: real_alter_rename_table_stmt, or shifting into the more complex form alter_rename_table_stmt: real_alter_rename_table_stmt HELPTOKEN.

This is another form of the textbook situation when yacc is used to parse if-else statements in a programming language: the rule stmt: IF cond THEN body | IF cond THEN body ELSE body is ambiguous (and yields a shift/reduce conflict) for exactly the same reason.

The solution here is also straight out of a textbook: one simply informs yacc of the relative priority between the two candidate rules. In this case, when faced with a neutral choice, we encourage yacc to shift. The particular mechanism is to tell yacc that one rule has a higher priority than another.

It just so happens however that the yacc language only allows us to set relative priorites of tokens, not rules. And here we have a problem, of the two rules that need to be prioritized, only one has a token to work with (the one with HELPTOKEN). Which token should we prioritze for the other?

Conveniently yacc knows about this trouble and offers us an awkward, but working solution: we can tell it "use for this rule the same priority level as an existing token, even though the token is not part of the rule". The syntax for this is rule %prec TOKEN.

We can then use this as follows:

alter_rename_table_stmt:
  real_alter_rename_table_stmt           %prec LOWTOKEN { $$ = $1 }
| real_alter_rename_table_stmt HELPTOKEN %prec HIGHTOKEN { help ... }

We could create two new pseudo-tokens for this (called LOWTOKEN and HIGHTOKEN) however conveniently we can also reuse otherwise valid tokens that have known relative priorities. We settled in our case on VALUES (low priority) and UMINUS (high priority).

Code generation

With the latter mechanism presented above the pattern

rule:
  somerule           %prec VALUES
| somerule HELPTOKEN %prec UMINUS { help ...}`

becomes super common, so we automate it with the following special syntax:

rule:
  somerule // EXTEND WITH HELP: XXX

And the code replacement in replace_help_rules.awk expands this to the form above automatically.

References

  1. https://www.gnu.org/software/bison/manual/html_node/Error-Recovery.html
  2. http://stackoverflow.com/questions/9796608/error-handling-in-yacc

# Functions

AsDArray attempts to retrieve a *DArray from an Expr, returning a *DArray and a flag signifying whether the assertion was successful.
AsDInt attempts to retrieve a DInt from an Expr, returning a DInt and a flag signifying whether the assertion was successful.
AsDString attempts to retrieve a DString from an Expr, returning a DString and a flag signifying whether the assertion was successful.
AsString pretty prints a node to a string.
AsStringWithFlags pretty prints a node to a string given specific flags.
CastTargetToDatumType produces a Type equivalent to the given SQL cast target type.
ContainsVars returns true if the expression contains any variables.
DatumTypeToColumnType produces a SQL column type equivalent to the given Datum type.
EmptyDTable returns a new, empty DTable.
ErrString pretty prints a node to a string.
EscapeSQLString returns an escaped SQL representation of the given string.
ExprDebugString generates a multi-line debug string with one node per line in Go format.
FindEqualComparisonFunction looks up an overload of the "=" operator for a given pair of input operand types.
FmtExpr returns FmtFlags that indicate how the pretty-printer should format expressions.
FmtIndexedVarFormat returns FmtFlags that customizes the printing of IndexedVars using the provided function.
FmtReformatTableNames returns FmtFlags that instructs the pretty-printer to substitute the printing of table names using the provided function.
FmtStarDatumFormat returns FmtFlags that customizes the printing of StarDatums using the provided function.
FormatNode recurses into a node for pretty-printing.
GenerateUniqueInt creates a unique int composed of the current time at a 10-microsecond granularity and the node-id.
GetBool gets DBool or an error (also treats NULL as false, not an error).
HasReturningClause determines if a ReturningClause is present, given a variant of the ReturningClause interface.
IsNumericOne returns true if the datum is a number and equal to one.
IsNumericZero returns true if the datum is a number and equal to zero.
LimitDecimalWidth limits d's precision (total number of digits) and scale (number of digits after the decimal point).
MakeDBool converts its argument to a *DBool, returning either DBoolTrue or DBoolFalse.
MakeDOid is a helper routine to create a DOid initialized from a DInt.
MakeDTimestamp creates a DTimestamp with specified precision.
MakeDTimestampTZ creates a DTimestampTZ with specified precision.
MakeDTimestampTZFromDate creates a DTimestampTZ from a DDate.
MakeIndexedVarHelper initializes an IndexedVarHelper structure.
MakePlaceholderInfo constructs an empty PlaceholderInfo.
MakeScanner makes a Scanner from str.
MakeSemaContext initializes a simple SemaContext suitable for "lightweight" type checking such as the one performed for default expressions.
MakeTestingEvalContext returns an EvalContext that includes a MemoryMonitor.
MustBeDArray attempts to retrieve a *DArray from an Expr, panicking if the assertion fails.
MustBeDInt attempts to retrieve a DInt from an Expr, panicking if the assertion fails.
MustBeDString attempts to retrieve a DString from an Expr, panicking if the assertion fails.
NewDArray returns a DArray containing elements of the specified type.
NewDBytes is a helper routine to create a *DBytes initialized from its argument.
NewDCollatedString is a helper routine to create a *DCollatedString.
NewDDate is a helper routine to create a *DDate initialized from its argument.
NewDDateFromTime constructs a *DDate from a time.Time in the provided time zone.
NewDFloat is a helper routine to create a *DFloat initialized from its argument.
NewDInt is a helper routine to create a *DInt initialized from its argument.
NewDIntVectorFromDArray is a helper routine to create a *DIntVector (implemented as a *DOidWrapper) initialized from an existing *DArray.
NewDName is a helper routine to create a *DName (implemented as a *DOidWrapper) initialized from a string.
NewDNameFromDString is a helper routine to create a *DName (implemented as a *DOidWrapper) initialized from an existing *DString.
NewDOid is a helper routine to create a *DOid initialized from a DInt.
NewDString is a helper routine to create a *DString initialized from its argument.
NewDTuple creates a *DTuple with the provided datums.
NewDTupleWithCap creates a *DTuple with the provided capacity.
NewDTupleWithLen creates a *DTuple with the provided length.
NewDUuid is a helper routine to create a *DUuid initialized from its argument.
NewFloatColType creates a type representing a FLOAT, optionally with a precision.
NewIdentAggregate returns an identAggregate (see comment on struct).
NewIndexedVar is a helper routine to create a standalone Indexedvar with the given index value.
NewInvalidNameErrorf initializes an error carrying the pg code CodeInvalidNameError.
NewOrdinalReference is a helper routine to create a standalone IndexedVar with the given index value.
NewPlaceholder allocates a Placeholder.
NewRegexpCache creates a new RegexpCache of the given size.
NewStrVal constructs a StrVal instance.
NewTestingEvalContext is a convenience version of MakeTestingEvalContext that returns a pointer.
NewTypedAndExpr returns a new AndExpr that is verified to be well-typed.
NewTypedComparisonExpr returns a new ComparisonExpr that is verified to be well-typed.
NewTypedNotExpr returns a new NotExpr that is verified to be well-typed.
NewTypedOrExpr returns a new OrExpr that is verified to be well-typed.
Parse parses a sql statement string and returns a list of Statements.
ParseDBool parses and returns the *DBool Datum value represented by the provided string, or an error if parsing is unsuccessful.
ParseDByte parses a string representation of hex encoded binary data.
ParseDDate parses and returns the *DDate Datum value represented by the provided string in the provided location, or an error if parsing is unsuccessful.
ParseDDecimal parses and returns the *DDecimal Datum value represented by the provided string, or an error if parsing is unsuccessful.
ParseDFloat parses and returns the *DFloat Datum value represented by the provided string, or an error if parsing is unsuccessful.
ParseDInt parses and returns the *DInt Datum value represented by the provided string, or an error if parsing is unsuccessful.
ParseDInterval parses and returns the *DInterval Datum value represented by the provided string, or an error if parsing is unsuccessful.
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.
ParseDTimestamp parses and returns the *DTimestamp Datum value represented by the provided string in UTC, or an error if parsing is unsuccessful.
ParseDTimestampTZ parses and returns the *DTimestampTZ Datum value represented by the provided string in the provided location, or an error if parsing is unsuccessful.
ParseDUuidFromBytes parses and returns the *DUuid Datum value represented by the provided input bytes, or an error.
ParseDUuidFromString parses and returns the *DUuid Datum value represented by the provided input string, or an error.
ParseExpr is a short-hand for parseExprs([]string{sql}).
ParseExprs is a short-hand for parseExprs(sql).
ParseOne parses a sql statement string, ensuring that it contains only a single statement, and returns that Statement.
ParseStringAs parses s as type t.
ParseTableName parses a table name.
ParseType parses a column type.
PGDisplayName returns the Postgres display name for a given type.
PGIOBuiltinPrefix returns the string prefix to a type's IO functions.
ReType ensures that the given numeric expression evaluates to the requested type, inserting a cast if necessary.
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.
SimilarEscape converts a SQL:2008 regexp pattern to POSIX style, so it can be used by our regexp engine.
SimpleVisit is a convenience wrapper for visitors that only have VisitPre code and don't return any results except an error.
StarExpr is a convenience function that represents an unqualified "*".
StmtDebugString generates multi-line debug strings in Go format for the expressions that are part of the given statement.
StripParens strips any parentheses surrounding an expression and returns the inner expression.
StripTypeFormatting removes the flag that extracts types from the format flags, so as to enable rendering expressions for which types have not been computed yet.
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.
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.
TypeCheckAndRequire performs type checking on the provided expression tree in an identical manner to TypeCheck.
UnwrapDatum returns the base Datum type for a provided datum, stripping an *DOidWrapper if present.
UnwrapType returns the base Type type for a provided type, stripping a *TOidWrapper if present.
ValidateRestartCheckpoint checks that a checkpoint name is our magic restart value.
WalkExpr traverses the nodes in an expression.
WalkExprConst is a variant of WalkExpr for visitors that do not modify the expression.
WalkStmt walks the entire parsed stmt calling WalkExpr on each expression, and replacing each expression with the one returned by WalkExpr.

# Constants

Ack indicates that the statement does not have a meaningful return.
No description provided by the author
No description provided by the author
AggregateClass is a builtin aggregate function.
ComparisonExpr.Operator.
No description provided by the author
FuncExpr.Type.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
The following operators will always be used with an associated SubOperator.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Direction values.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
BinaryExpr.Operator.
BinaryExpr.Operator.
BinaryExpr.Operator.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
BinaryExpr.Operator.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
CopyIn indicates a COPY FROM statement.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
DDL indicates that the statement mutates the database schema.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Direction values.
No description provided by the author
No description provided by the author
No description provided by the author
Direction values.
No description provided by the author
DiscardModeAll represents a DISCARD ALL statement.
No description provided by the author
FuncExpr.Type.
BinaryExpr.Operator.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
DropBehavior values.
DropBehavior values.
DropBehavior values.
No description provided by the author
No description provided by the author
No description provided by the author
ComparisonExpr.Operator.
No description provided by the author
No description provided by the author
No description provided by the author
Union.Type.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
BinaryExpr.Operator.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ComparisonExpr.Operator.
GeneratorClass is a builtin generator function.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ComparisonExpr.Operator.
No description provided by the author
No description provided by the author
No description provided by the author
UserPriority values.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ComparisonExpr.Operator.
No description provided by the author
No description provided by the author
ComparisonExpr.Operator.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Union.Type.
No description provided by the author
No description provided by the author
InvalidColIdx is the index value of a non-initialized IndexedVar.
ComparisonExpr.Operator.
No description provided by the author
ComparisonExpr.Operator.
ComparisonExpr.Operator.
ComparisonExpr.Operator.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ComparisonExpr.Operator.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ComparisonExpr.Operator.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
UserPriority values.
No description provided by the author
BinaryExpr.Operator.
No description provided by the author
ComparisonExpr.Operator.
No description provided by the author
MaxInt is the maximum value of an int.
MaxUint is the maximum value of an uint.
BinaryExpr.Operator.
No description provided by the author
BinaryExpr.Operator.
No description provided by the author
BinaryExpr.Operator.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ComparisonExpr.Operator.
No description provided by the author
No description provided by the author
No description provided by the author
UserPriority values.
No description provided by the author
NormalClass is a standard builtin function.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ComparisonExpr.Operator.
ComparisonExpr.Operator.
ComparisonExpr.Operator.
The values for NullType.
ComparisonExpr.Operator.
ComparisonExpr.Operator.
ComparisonExpr.Operator.
The values for NullType.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
OrderByColumn is the regular "by expression/column" ORDER BY specification.
OrderByIndex enables the user to specify a given index' columns implicitly.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
BinaryExpr.Operator.
No description provided by the author
No description provided by the author
BinaryExpr.Operator.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ReadWriteMode values.
ReadWriteMode values.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ComparisonExpr.Operator.
No description provided by the author
ComparisonExpr.Operator.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
RestartSavepointName is the only savepoint name that we accept, modulo capitalization.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Rows indicates that the statement returns the affected rows after the statement was applied.
No description provided by the author
RowsAffected indicates that the statement returns the count of affected rows.
BinaryExpr.Operator.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
IsolationLevel values.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
The values for NullType.
No description provided by the author
ComparisonExpr.Operator.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
IsolationLevel values.
ComparisonExpr.Operator.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
TimestampOutputFormat is used to output all timestamps.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
UnaryExpr.Operator.
UnaryExpr.Operator.
UnaryExpr.Operator.
No description provided by the author
No description provided by the author
No description provided by the author
Union.Type.
No description provided by the author
Unknown indicates that the statement does not have a known return style at the time of parsing.
No description provided by the author
IsolationLevel values.
ReadWriteMode values.
UserPriority values.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ValidationDefault is the default validation behavior (immediate).
ValidationSkip skips validation of any existing data.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
WindowClass is a builtin window function.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

AbsentReturningClause is a ReturningClause variant representing the absence of a RETURNING clause.
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.
AllBuiltinNames is an array containing all the built-in function names, sorted in alphabetical order.
AllHelp contains an overview of all statements with help messages.
BinOps contains the binary operations indexed by operation type.
Builtins contains the built-in functions indexed by name.
CmpOps contains the comparison operations indexed by operation type.
DBoolFalse is a pointer to the DBool(false) value and can be used in comparisons against Datum types.
DBoolTrue is a pointer to the DBool(true) value and can be used in comparisons against Datum types.
DecimalCtx is the default context for decimal operations.
DecimalOne represents the constant 1 as DECIMAL.
DNull is the NULL Datum.
DZero is the zero-valued integer Datum.
ExactCtx is a decimal context with exact precision.
FmtAnonymize instructs the pretty-printer to remove any name but function names.
FmtArrays instructs the pretty-printer to print strings without wrapping quotes, if the string contains no special characters.
FmtBareIdentifiers instructs the pretty-printer to print identifiers without wrapping quotes in any case.
FmtBareStrings instructs the pretty-printer to print strings without wrapping quotes, if the string contains no special characters.
FmtCheckEquivalence instructs the pretty-printer to produce a representation that can be used to check equivalence of expressions.
FmtHideConstants instructs the pretty-printer to produce a representation that does not disclose query-specific data.
FmtParsable instructs the pretty-printer to produce a representation that can be parsed into an equivalent expression (useful for serialization of expressions).
FmtShowTypes instructs the pretty-printer to annotate expressions with their resolved types.
FmtSimple instructs the pretty-printer to produce a straightforward representation.
FmtSimpleQualified instructs the pretty-printer to produce a straightforward representation that qualifies table names.
FmtSimpleWithPasswords instructs the pretty-printer to produce a straightforward representation that does not suppress passwords.
Generators is a map from name to slice of Builtins for all built-in generators.
HelpMessages is the registry of all help messages, keyed by the top-level statement that they document.
HighPrecisionCtx is a decimal context with high precision.
OidToType maps Postgres object IDs to CockroachDB types.
RoundCtx is a decimal context with high precision and RoundHalfEven rounding.
TypeAny can be any type.
TypeAnyArray is the type of a DArray with a wildcard parameterized type.
TypeArray is the type family of a DArray.
TypeBool is the type of a DBool.
TypeBytes is the type of a DBytes.
TypeCollatedString is the type family of a DString.
TypeDate is the type of a DDate.
TypeDecimal is the type of a DDecimal.
TypeFloat is the type of a DFloat.
TypeInt is the type of a DInt.
TypeInterval is the type of a DInterval.
TypeIntVector is a type-alias for a TypeIntArray with a different OID.
TypeName is a type-alias for TypeString with a different OID.
TypeNameArray is the type family of a DArray containing the Name alias type.
TypeNull is the type of a DNull.
TypeOid is the type of an OID.
TypePlaceholder is the type family of a placeholder.
TypeRegClass is the type of an regclass OID variant.
TypeRegNamespace is the type of an regnamespace OID variant.
TypeRegProc is the type of an regproc OID variant.
TypeRegProcedure is the type of an regprocedure OID variant.
TypeRegType is the type of an regtype OID variant.
TypesAnyNonArray contains all non-array types.
TypeString is the type of a DString.
TypeTable is the type family of a DTable.
TypeTimestamp is the type of a DTimestamp.
TypeTimestampTZ is the type of a DTimestampTZ.
TypeTuple is the type family of a DTuple.
TypeUUID is the type of a DUuid.
UnaryOps contains the unary operations indexed by operation type.

# Structs

AliasClause represents an alias, optionally with a column list: "AS name" or "AS name(col1, col2)".
AliasedTableExpr represents a table expression coupled with an optional alias.
AllColumnsSelector corresponds to a selection of all columns in a table when used in a SELECT clause.
AllTablesSelector corresponds to a selection of all tables in a database, e.g.
AlterTable represents an ALTER TABLE statement.
AlterTableAddColumn represents an ADD COLUMN command.
AlterTableAddConstraint represents an ADD CONSTRAINT command.
AlterTableDropColumn represents a DROP COLUMN command.
AlterTableDropConstraint represents a DROP CONSTRAINT command.
AlterTableDropNotNull represents an ALTER COLUMN DROP NOT NULL command.
AlterTableSetDefault represents an ALTER COLUMN SET DEFAULT or DROP DEFAULT command.
AlterTableValidateConstraint represents a VALIDATE CONSTRAINT command.
AndExpr represents an AND expression.
AnnotateTypeExpr represents a ANNOTATE_TYPE(expr, type) expression.
Array represents an array constructor.
ArrayColType represents an ARRAY column type.
ArrayFlatten represents a subquery array constructor.
ArraySubscript corresponds to the syntax `<name>[ ..
AsOfClause represents an as of time.
Backup represents a BACKUP statement.
BeginTransaction represents a BEGIN statement.
BinaryExpr represents a binary value expression.
BinOp is a binary operator.
BoolColType represents a BOOLEAN type.
Builtin is a built-in function.
BytesColType represents a BYTES or BLOB type.
CancelJob represents a CANCEL JOB statement.
CancelQuery represents a CANCEL QUERY statement.
CaseExpr represents a CASE expression.
CastExpr represents a CAST(expr AS type) expression.
CheckConstraintTableDef represents a check constraint within a CREATE TABLE statement.
CmpOp is a comparison operator.
CoalesceExpr represents a COALESCE or IFNULL expression.
CollatedStringColType represents a STRING, CHAR or VARCHAR type with a collation locale.
CollateExpr represents an (expr COLLATE locale) expression.
CollationEnvironment stores the state needed by NewDCollatedString to construct collation keys efficiently.
ColumnCheckConstraint represents either a check on a column.
ColumnDefault represents a DEFAULT clause for a column.
ColumnFamilyConstraint represents FAMILY on a column.
ColumnFKConstraint represents a FK-constaint on a column.
ColumnItem corresponds to the name of a column or sub-item of a column in an expression.
ColumnTableDef represents a column definition within a CREATE TABLE statement.
ColumnTableDefCheckExpr represents a check constraint on a column definition within a CREATE TABLE statement.
CommitTransaction represents a COMMIT statement.
ComparisonExpr represents a two-value comparison expression.
ContainsWindowVisitor checks if walked expressions contain window functions.
CopyFrom represents a COPY FROM statement.
CreateDatabase represents a CREATE DATABASE statement.
CreateIndex represents a CREATE INDEX statement.
CreateTable represents a CREATE TABLE statement.
CreateUser represents a CREATE USER statement.
CreateView represents a CREATE VIEW statement.
DArray is the array Datum.
DateColType represents a DATE type.
DCollatedString is the Datum for strings with a locale.
DDecimal is the decimal Datum.
Deallocate represents a DEALLOCATE statement.
DecimalColType represents a DECIMAL or NUMERIC type.
DefaultVal represents the DEFAULT expression.
Delete represents a DELETE statement.
DInterval is the interval Datum.
Discard represents a DISCARD statement.
DOid is the Postgres OID datum.
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).
DropDatabase represents a DROP DATABASE statement.
DropIndex represents a DROP INDEX statement.
DropTable represents a DROP TABLE statement.
DropUser represents a DROP USER statement.
DropView represents a DROP VIEW statement.
DTable is the table Datum.
DTimestamp is the timestamp Datum.
DTimestampTZ is the timestamp Datum that is rendered with session offset.
DTuple is the tuple Datum.
DUuid is the UUID Datum.
EvalContext defines the context in which to evaluate an expression, allowing the retrieval of state such as the node ID or statement start time.
Execute represents an EXECUTE statement.
ExistsExpr represents an EXISTS expression.
Explain represents an EXPLAIN statement.
FamilyTableDef represents a family definition within a CREATE TABLE statement.
FloatColType represents a REAL, DOUBLE or FLOAT type.
ForeignKeyConstraintTableDef represents a FOREIGN KEY constraint in the AST.
From represents a FROM clause.
FuncExpr represents a function call.
FunctionDefinition implements a reference to the (possibly several) overloads for a built-in function.
Grant represents a GRANT statement.
HelpMessage describes a contextual help message.
HelpMessageBody defines the body of a help text.
HomogeneousType is a typeList implementation that accepts any arguments, as long as all are the same type or NULL.
IfExpr represents an IF expression.
Import represents a IMPORT statement.
IndexedRow is a row with a corresponding index.
IndexedVar is a VariableExpr that can be used as a leaf in expressions; it represents a dynamic value.
IndexedVarHelper wraps an IndexedVarContainer (an interface) and creates IndexedVars bound to that container.
IndexElem represents a column with a direction in a CREATE INDEX statement.
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.
IndexTableDef represents an index definition within a CREATE TABLE statement.
IndirectionExpr represents a subscript expression.
Insert represents an INSERT statement.
IntColType represents an INT, INTEGER, SMALLINT or BIGINT type.
InterleaveDef represents an interleave definition within a CREATE TABLE or CREATE INDEX statement.
IntervalColType represents an INTERVAL type.
IsAggregateVisitor checks if walked expressions contain aggregate functions.
IsOfTypeExpr represents an IS {,NOT} OF (type_list) expression.
JoinTableExpr represents a TableExpr that's a JOIN operation.
KVOption is a key-value option.
Limit represents a LIMIT clause.
MaxAggregate keeps track of the largest value passed to Add.
MinAggregate keeps track of the smallest value passed to Add.
MultipleResultsError is returned by QueryRow when more than one result is encountered.
NameColType represents a a NAME type.
NamedColumnQualification wraps a NamedColumnQualification with a name.
NaturalJoinCond represents a NATURAL join condition.
NoReturningClause represents the absence of a RETURNING clause.
NormalizableTableName implements an editable table name.
NotExpr represents a NOT expression.
NotNullConstraint represents NOT NULL on a column.
NullConstraint represents NULL on a column.
NullIfExpr represents a NULLIF expression.
NumVal represents a constant numeric value.
OidColType represents an OID type, which is the type of system object identifiers.
OnConflict represents an `ON CONFLICT (columns) DO UPDATE SET exprs WHERE where` clause.
OnJoinCond represents an ON join condition.
Order represents an ordering expression.
OrExpr represents an OR expression.
ParenExpr represents a parenthesized expression.
ParenSelect represents a parenthesized SELECT/UNION/VALUES statement.
ParenTableExpr represents a parenthesized TableExpr.
Parser wraps a scanner, parser and other utilities present in the parser package.
PauseJob represents a PAUSE JOB statement.
Placeholder represents a named placeholder.
PlaceholderInfo defines the interface to SQL placeholders.
Prepare represents a PREPARE statement.
PrimaryKeyConstraint represents NULL on a column.
RangeCond represents a BETWEEN or a NOT BETWEEN expression.
A RegexpCache is a cache used to store compiled regular expressions.
ReleaseSavepoint represents a RELEASE SAVEPOINT <name> statement.
RenameColumn represents a RENAME COLUMN statement.
RenameDatabase represents a RENAME DATABASE statement.
RenameIndex represents a RENAME INDEX statement.
RenameTable represents a RENAME TABLE or RENAME VIEW statement.
ResolvableFunctionReference implements the editable reference cell of a FuncExpr.
Restore represents a RESTORE statement.
ResumeJob represents a RESUME JOB statement.
ReturningNothing represents RETURNING NOTHING.
Revoke represents a REVOKE statements.
RollbackToSavepoint represents a ROLLBACK TO SAVEPOINT <name> statement.
RollbackTransaction represents a ROLLBACK statement.
Savepoint represents a SAVEPOINT <name> statement.
Scanner lexes SQL statements.
Scatter represents an `ALTER TABLE/INDEX .
Select represents a SelectStatement with an ORDER and/or LIMIT.
SelectClause represents a SELECT statement.
SelectExpr represents a SELECT expression.
SemaContext defines the context in which to perform semantic analysis on an expression syntax tree.
SetClusterSetting represents a SET CLUSTER SETTING statement.
SetDefaultIsolation represents a SET SESSION CHARACTERISTICS AS TRANSACTION statement.
SetTransaction represents a SET TRANSACTION statement.
SetVar represents a SET or RESET statement.
ShowBackup represents a SHOW BACKUP statement.
ShowClusterSetting represents a SHOW CLUSTER SETTING statement.
ShowColumns represents a SHOW COLUMNS statement.
ShowConstraints represents a SHOW CONSTRAINTS statement.
ShowCreateTable represents a SHOW CREATE TABLE statement.
ShowCreateView represents a SHOW CREATE VIEW statement.
ShowDatabases represents a SHOW DATABASES statement.
ShowFingerprints represents a SHOW EXPERIMENTAL_FINGERPRINTS statement.
ShowGrants represents a SHOW GRANTS statement.
ShowIndex represents a SHOW INDEX statement.
ShowJobs represents a SHOW JOBS statement.
ShowQueries represents a SHOW QUERIES statement.
ShowRanges represents a SHOW TESTING_RANGES statement.
ShowSessions represents a SHOW SESSIONS statement.
ShowTables represents a SHOW TABLES statement.
ShowTrace represents a SHOW TRACE FOR SESSION statement.
ShowTransactionStatus represents a SHOW TRANSACTION STATUS statement.
ShowUsers represents a SHOW USERS statement.
ShowVar represents a SHOW statement.
Split represents an `ALTER TABLE/INDEX .
StatementSource encapsulates one of the other statements as a data source.
StringColType represents a STRING, CHAR or VARCHAR type.
StrVal represents a constant string value.
Subquery represents a subquery.
TableName corresponds to the name of a table in a FROM clause, INSERT or UPDATE statement (and possibly other places).
TableNameWithIndex represents a "table@index", used in statements that specifically refer to an index.
TableRef represents a numeric table reference.
TargetList represents a list of targets.
TArray is the type of a DArray.
TCollatedString is the type of strings with a locale.
TestingRelocate represents an `ALTER TABLE/INDEX .
TimestampColType represents a TIMESTAMP type.
TimestampTZColType represents a TIMESTAMP type.
TPlaceholder is the type of a placeholder.
TransactionModes holds the transaction modes for a transaction.
Truncate represents a TRUNCATE statement.
TTable is the type of a DTable.
Tuple represents a parenthesized list of expressions.
UnaryExpr represents a unary value expression.
UnaryOp is a unary operator.
UnionClause represents a UNION statement.
UniqueConstraint represents UNIQUE on a column.
UniqueConstraintTableDef represents a unique constraint within a CREATE TABLE statement.
UnqualifiedStar corresponds to a standalone '*' in an expression or a '*' as name part of an UnresolvedName.
Update represents an UPDATE statement.
UpdateExpr represents an update expression.
UsingJoinCond represents a USING join condition.
UUIDColType represents a UUID type.
ValuesClause represents a VALUES clause.
VariadicType is a typeList implementation which accepts any number of arguments and matches when each argument is either NULL or of the type typ.
VectorColType is the base for VECTOR column types, which are Postgres's older, limited version of ARRAYs.
When represents a WHEN sub-expression.
Where represents a WHERE or HAVING clause.
WindowDef represents a single window definition expression.
WindowFrame is a view into a subset of data over which calculations are made.

# Interfaces

AggregateFunc accumulates the result of a function of a Datum.
AlterTableCmd represents a table modification operation.
CastTargetType represents a type that is a valid cast target.
ColumnMutationCmd is the subset of AlterTableCmds that modify an existing column.
ColumnQualification represents a constraint on a column.
ColumnType represents a type in a column definition.
CompositeDatum is a Datum that may require composite encoding in indexes.
Constant is an constant literal expression which may be resolved to more than one type.
ConstraintTableDef represents a constraint definition within a CREATE TABLE statement.
DatabaseQualifiable identifiers can be qualifed with a database name.
Datum represents a SQL value.
EvalPlanner is a limited planner that can be used from EvalContext.
Expr represents an expression.
FunctionReference is the common interface to UnresolvedName and QualifiedFunctionName.
HiddenFromShowQueries is a pseudo-interface to be implemented by statements that should not show up in SHOW QUERIES (and are hence not cancellable using CANCEL QUERY either).
HiddenFromStats is a pseudo-interface to be implemented by statements that should not show up in per-app statistics.
IndependentFromParallelizedPriors is a pseudo-interface to be implemented by statements which do not force parallel statement execution synchronization when they run.
IndexedVarContainer provides the implementation of TypeCheck, Eval, and String for IndexedVars.
JoinCond represents a join condition.
NamePart is the interface for the sub-parts of an UnresolvedName or the Selector/Context members of ColumnItem and FunctionName.
NodeFormatter is implemented by nodes that can be pretty-printed.
ReturningClause represents the returning clause on a statement.
SelectStatement represents any SELECT statement.
Statement represents a statement.
TableDef represents a column, index or constraint definition within a CREATE TABLE statement.
TableExpr represents a table expression.
TableNameReference implements the editable cell of a TableExpr that refers to a single table.
TablePattern is the common interface to UnresolvedName, TableName and AllTablesSelector.
Type represents a SQL type.
TypedExpr represents a well-typed expression.
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).
VariableExpr is an Expr that may change per row.
VarName is the common interface to UnresolvedName, ColumnItem and AllColumnsSelector for use in expression contexts.
Visitor defines methods that are called for nodes during an expression or statement walk.
WalkableStmt is implemented by statements that can appear inside an expression (selects) or we want to start a walk from (using WalkStmt).
WindowFunc performs a computation on each row using data from a provided WindowFrame.

# Type aliases

AlterTableCmds represents a list of table alterations.
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.
ArraySubscripts represents a sequence of one or more array subscripts.
BinaryOperator represents a binary operator.
ColumnCollation represents a COLLATE clause for a column.
ColumnID is a custom type for ColumnDescriptor IDs.
ComparisonOperator represents a binary operator.
Datums is a slice of Datum values.
DBool is the boolean Datum.
DBytes is the bytes Datum.
DDate is the date Datum represented as the number of days after the Unix epoch.
DFloat is the float Datum.
DInt is the int Datum.
Direction for ordering results.
DiscardMode is an enum of the various discard modes.
DropBehavior represents options for dropping schema elements.
DString is the string Datum.
Exprs represents a list of value expressions.
FunctionClass specifies the class of the builtin function.
GroupBy represents a GROUP BY clause.
ID is a custom type for {Database,Table}Descriptor IDs.
IndexElemList is list of IndexElem.
IndexID is a custom type for IndexDescriptor IDs.
IsolationLevel holds the isolation level for a transaction.
KVOptions is a list of KVOptions.
A Name is an SQL identifier.
A NameList is a list of identifiers.
NameParts represents a combination of names with array and sub-field subscripts.
Nullability represents either NULL, NOT NULL or an unspecified value (silent NULL).
OrderBy represents an ORDER By clause.
OrderType indicates which type of expression is used in ORDER BY.
PlaceholderTypes relates placeholder names to their resolved type.
QueryArguments relates placeholder names to their provided query argument.
ReadWriteMode holds the read write mode for a transaction.
ReturningExprs represents RETURNING expressions.
SearchPath represents a list of namespaces to search builtins in.
SelectExprs represents SELECT expressions.
SimpleVisitFn is a function that is run for every node in the VisitPre stage; see SimpleVisit.
StatementList is a list of statements.
StatementType is the enumerated type for Statement return styles on the wire.
TableDefs represents a list of table definitions.
TableExprs represents a list of table expressions.
TableNameReferences corresponds to a comma-delimited list of table name references.
TableNames represents a comma separated list (see the Format method) of table names.
TableNameWithIndexList is a list of indexes.
TablePatterns implement a comma-separated list of table patterns.
TTuple is the type of a DTuple.
TypedExprs represents a list of well-typed value expressions.
UnaryOperator represents a unary operator.
UnionType represents one of the three set operations in sql.
UnresolvedName holds the initial syntax of a name as determined during parsing.
UnresolvedNames corresponds to a comma-separate list of unresolved names.
UpdateExprs represents a list of update expressions.
UserPriority holds the user priority for a transaction.
ValidationBehavior specifies whether or not a constraint is validated.
Window represents a WINDOW clause.