parser

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

README

Generated Documentation and Embedded Help Texts

Many parts of the parser package include special consideration for generation or other production of user-facing documentation. This includes interactive help messages, generated documentation of the set of available functions, or diagrams of the various expressions.

Generated documentation is produced and maintained at compile time, while the interactive, contextual help is returned at runtime.

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

We use the docgen tool to produce the generated documentation files that are then included in the broader (handwritten) published documentation.

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 priorities 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 prioritize 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.

Generated Documentation

Documentation of the SQL functions and operators is generated by the docgen utility, using make generate PKG=./docs/.... The markdown-formatted files are kept in docs/generated/sql and should be re-generated whenever the functions/operators they document change, and indeed if regenerating produces a diff, a CI failure is expected.

References

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

Documentation

Index

Constants

View Source
const ABORT = lexbase.ABORT
View Source
const ABSOLUTE = lexbase.ABSOLUTE
View Source
const ACCESS = lexbase.ACCESS
View Source
const ACTION = lexbase.ACTION
View Source
const ADD = lexbase.ADD
View Source
const ADMIN = lexbase.ADMIN
View Source
const AFTER = lexbase.AFTER
View Source
const AGGREGATE = lexbase.AGGREGATE
View Source
const ALL = lexbase.ALL
View Source
const ALTER = lexbase.ALTER
View Source
const ALWAYS = lexbase.ALWAYS
View Source
const ANALYSE = lexbase.ANALYSE
View Source
const ANALYZE = lexbase.ANALYZE
View Source
const AND = lexbase.AND
View Source
const AND_AND = lexbase.AND_AND
View Source
const ANNOTATE_TYPE = lexbase.ANNOTATE_TYPE
View Source
const ANY = lexbase.ANY
View Source
const ARRAY = lexbase.ARRAY
View Source
const AS = lexbase.AS
View Source
const ASC = lexbase.ASC
View Source
const ASENSITIVE = lexbase.ASENSITIVE
View Source
const ASYMMETRIC = lexbase.ASYMMETRIC
View Source
const AS_LA = lexbase.AS_LA
View Source
const AT = lexbase.AT
View Source
const ATTRIBUTE = lexbase.ATTRIBUTE
View Source
const AUTHORIZATION = lexbase.AUTHORIZATION
View Source
const AUTOMATIC = lexbase.AUTOMATIC
View Source
const AVAILABILITY = lexbase.AVAILABILITY
View Source
const BACKUP = lexbase.BACKUP
View Source
const BACKUPS = lexbase.BACKUPS
View Source
const BACKWARD = lexbase.BACKWARD
View Source
const BCONST = lexbase.BCONST
View Source
const BEFORE = lexbase.BEFORE
View Source
const BEGIN = lexbase.BEGIN
View Source
const BETWEEN = lexbase.BETWEEN
View Source
const BIGINT = lexbase.BIGINT
View Source
const BIGSERIAL = lexbase.BIGSERIAL
View Source
const BINARY = lexbase.BINARY
View Source
const BIT = lexbase.BIT
View Source
const BITCONST = lexbase.BITCONST
View Source
const BOOLEAN = lexbase.BOOLEAN
View Source
const BOTH = lexbase.BOTH
View Source
const BOX2D = lexbase.BOX2D
View Source
const BUCKET_COUNT = lexbase.BUCKET_COUNT
View Source
const BUNDLE = lexbase.BUNDLE
View Source
const BY = lexbase.BY
View Source
const CACHE = lexbase.CACHE
View Source
const CANCEL = lexbase.CANCEL
View Source
const CANCELQUERY = lexbase.CANCELQUERY
View Source
const CASCADE = lexbase.CASCADE
View Source
const CASE = lexbase.CASE
View Source
const CAST = lexbase.CAST
View Source
const CBRT = lexbase.CBRT
View Source
const CHANGEFEED = lexbase.CHANGEFEED
View Source
const CHAR = lexbase.CHAR
View Source
const CHARACTER = lexbase.CHARACTER
View Source
const CHARACTERISTICS = lexbase.CHARACTERISTICS
View Source
const CHECK = lexbase.CHECK
View Source
const CLOSE = lexbase.CLOSE
View Source
const CLUSTER = lexbase.CLUSTER
View Source
const COALESCE = lexbase.COALESCE
View Source
const COLLATE = lexbase.COLLATE
View Source
const COLLATION = lexbase.COLLATION
View Source
const COLUMN = lexbase.COLUMN
View Source
const COLUMNS = lexbase.COLUMNS
View Source
const COMMENT = lexbase.COMMENT
View Source
const COMMENTS = lexbase.COMMENTS
View Source
const COMMIT = lexbase.COMMIT
View Source
const COMMITTED = lexbase.COMMITTED
View Source
const COMPACT = lexbase.COMPACT
View Source
const COMPLETE = lexbase.COMPLETE
View Source
const COMPLETIONS = lexbase.COMPLETIONS
View Source
const CONCAT = lexbase.CONCAT
View Source
const CONCURRENTLY = lexbase.CONCURRENTLY
View Source
const CONFIGURATION = lexbase.CONFIGURATION
View Source
const CONFIGURATIONS = lexbase.CONFIGURATIONS
View Source
const CONFIGURE = lexbase.CONFIGURE
View Source
const CONFLICT = lexbase.CONFLICT
View Source
const CONNECTION = lexbase.CONNECTION
View Source
const CONSTRAINT = lexbase.CONSTRAINT
View Source
const CONSTRAINTS = lexbase.CONSTRAINTS
View Source
const CONTAINED_BY = lexbase.CONTAINED_BY
View Source
const CONTAINS = lexbase.CONTAINS
View Source
const CONTROLCHANGEFEED = lexbase.CONTROLCHANGEFEED
View Source
const CONTROLJOB = lexbase.CONTROLJOB
View Source
const CONVERSION = lexbase.CONVERSION
View Source
const CONVERT = lexbase.CONVERT
View Source
const COPY = lexbase.COPY
View Source
const COVERING = lexbase.COVERING
View Source
const CREATE = lexbase.CREATE
View Source
const CREATEDB = lexbase.CREATEDB
View Source
const CREATELOGIN = lexbase.CREATELOGIN
View Source
const CREATEROLE = lexbase.CREATEROLE
View Source
const CROSS = lexbase.CROSS
View Source
const CSV = lexbase.CSV
View Source
const CUBE = lexbase.CUBE
View Source
const CURRENT = lexbase.CURRENT
View Source
const CURRENT_CATALOG = lexbase.CURRENT_CATALOG
View Source
const CURRENT_DATE = lexbase.CURRENT_DATE
View Source
const CURRENT_ROLE = lexbase.CURRENT_ROLE
View Source
const CURRENT_SCHEMA = lexbase.CURRENT_SCHEMA
View Source
const CURRENT_TIME = lexbase.CURRENT_TIME
View Source
const CURRENT_TIMESTAMP = lexbase.CURRENT_TIMESTAMP
View Source
const CURRENT_USER = lexbase.CURRENT_USER
View Source
const CURSOR = lexbase.CURSOR
View Source
const CYCLE = lexbase.CYCLE
View Source
const DATA = lexbase.DATA
View Source
const DATABASE = lexbase.DATABASE
View Source
const DATABASES = lexbase.DATABASES
View Source
const DATE = lexbase.DATE
View Source
const DAY = lexbase.DAY
View Source
const DEALLOCATE = lexbase.DEALLOCATE
View Source
const DEBUG_PAUSE_ON = lexbase.DEBUG_PAUSE_ON
View Source
const DEC = lexbase.DEC
View Source
const DECIMAL = lexbase.DECIMAL
View Source
const DECLARE = lexbase.DECLARE
View Source
const DEFAULT = lexbase.DEFAULT
View Source
const DEFAULTS = lexbase.DEFAULTS
View Source
const DEFERRABLE = lexbase.DEFERRABLE
View Source
const DEFERRED = lexbase.DEFERRED
View Source
const DELETE = lexbase.DELETE
View Source
const DELIMITER = lexbase.DELIMITER
View Source
const DESC = lexbase.DESC
View Source
const DESTINATION = lexbase.DESTINATION
View Source
const DETACHED = lexbase.DETACHED
View Source
const DISCARD = lexbase.DISCARD
View Source
const DISTINCT = lexbase.DISTINCT
View Source
const DO = lexbase.DO
View Source
const DOMAIN = lexbase.DOMAIN
View Source
const DOT_DOT = lexbase.DOT_DOT
View Source
const DOUBLE = lexbase.DOUBLE
View Source
const DROP = lexbase.DROP
View Source
const ELSE = lexbase.ELSE
View Source
const ENCODING = lexbase.ENCODING
View Source
const ENCRYPTED = lexbase.ENCRYPTED
View Source
const ENCRYPTION_PASSPHRASE = lexbase.ENCRYPTION_PASSPHRASE
View Source
const END = lexbase.END
View Source
const ENUM = lexbase.ENUM
View Source
const ENUMS = lexbase.ENUMS
View Source
const ERROR = lexbase.ERROR
View Source
const ESCAPE = lexbase.ESCAPE
View Source
const EXCEPT = lexbase.EXCEPT
View Source
const EXCLUDE = lexbase.EXCLUDE
View Source
const EXCLUDING = lexbase.EXCLUDING
View Source
const EXECUTE = lexbase.EXECUTE
View Source
const EXECUTION = lexbase.EXECUTION
View Source
const EXISTS = lexbase.EXISTS
View Source
const EXPERIMENTAL = lexbase.EXPERIMENTAL
View Source
const EXPERIMENTAL_AUDIT = lexbase.EXPERIMENTAL_AUDIT
View Source
const EXPERIMENTAL_FINGERPRINTS = lexbase.EXPERIMENTAL_FINGERPRINTS
View Source
const EXPERIMENTAL_RELOCATE = lexbase.EXPERIMENTAL_RELOCATE
View Source
const EXPERIMENTAL_REPLICA = lexbase.EXPERIMENTAL_REPLICA
View Source
const EXPIRATION = lexbase.EXPIRATION
View Source
const EXPLAIN = lexbase.EXPLAIN
View Source
const EXPORT = lexbase.EXPORT
View Source
const EXTENSION = lexbase.EXTENSION
View Source
const EXTRACT = lexbase.EXTRACT
View Source
const EXTRACT_DURATION = lexbase.EXTRACT_DURATION
View Source
const FAILURE = lexbase.FAILURE
View Source
const FALSE = lexbase.FALSE
View Source
const FAMILY = lexbase.FAMILY
View Source
const FCONST = lexbase.FCONST
View Source
const FETCH = lexbase.FETCH
View Source
const FETCHTEXT = lexbase.FETCHTEXT
View Source
const FETCHTEXT_PATH = lexbase.FETCHTEXT_PATH
View Source
const FETCHVAL = lexbase.FETCHVAL
View Source
const FETCHVAL_PATH = lexbase.FETCHVAL_PATH
View Source
const FILES = lexbase.FILES
View Source
const FILTER = lexbase.FILTER
View Source
const FIRST = lexbase.FIRST
View Source
const FLOAT = lexbase.FLOAT
View Source
const FLOAT4 = lexbase.FLOAT4
View Source
const FLOAT8 = lexbase.FLOAT8
View Source
const FLOORDIV = lexbase.FLOORDIV
View Source
const FOLLOWING = lexbase.FOLLOWING
View Source
const FOR = lexbase.FOR
View Source
const FORCE = lexbase.FORCE
View Source
const FORCE_INDEX = lexbase.FORCE_INDEX
View Source
const FORCE_ZIGZAG = lexbase.FORCE_ZIGZAG
View Source
const FOREIGN = lexbase.FOREIGN
View Source
const FORWARD = lexbase.FORWARD
View Source
const FROM = lexbase.FROM
View Source
const FULL = lexbase.FULL
View Source
const FUNCTION = lexbase.FUNCTION
View Source
const FUNCTIONS = lexbase.FUNCTIONS
View Source
const GENERATED = lexbase.GENERATED
View Source
const GENERATED_ALWAYS = lexbase.GENERATED_ALWAYS
View Source
const GENERATED_BY_DEFAULT = lexbase.GENERATED_BY_DEFAULT
View Source
const GEOGRAPHY = lexbase.GEOGRAPHY
View Source
const GEOMETRY = lexbase.GEOMETRY
View Source
const GEOMETRYCOLLECTION = lexbase.GEOMETRYCOLLECTION
View Source
const GEOMETRYCOLLECTIONM = lexbase.GEOMETRYCOLLECTIONM
View Source
const GEOMETRYCOLLECTIONZ = lexbase.GEOMETRYCOLLECTIONZ
View Source
const GEOMETRYCOLLECTIONZM = lexbase.GEOMETRYCOLLECTIONZM
View Source
const GEOMETRYM = lexbase.GEOMETRYM
View Source
const GEOMETRYZ = lexbase.GEOMETRYZ
View Source
const GEOMETRYZM = lexbase.GEOMETRYZM
View Source
const GLOBAL = lexbase.GLOBAL
View Source
const GOAL = lexbase.GOAL
View Source
const GRANT = lexbase.GRANT
View Source
const GRANTS = lexbase.GRANTS
View Source
const GREATER_EQUALS = lexbase.GREATER_EQUALS
View Source
const GREATEST = lexbase.GREATEST
View Source
const GROUP = lexbase.GROUP
View Source
const GROUPING = lexbase.GROUPING
View Source
const GROUPS = lexbase.GROUPS
View Source
const HASH = lexbase.HASH
View Source
const HAVING = lexbase.HAVING
View Source
const HELPTOKEN = lexbase.HELPTOKEN
View Source
const HIGH = lexbase.HIGH
View Source
const HISTOGRAM = lexbase.HISTOGRAM
View Source
const HOLD = lexbase.HOLD
View Source
const HOUR = lexbase.HOUR
View Source
const ICONST = lexbase.ICONST
View Source
const IDENT = lexbase.IDENT
View Source
const IDENTITY = lexbase.IDENTITY
View Source
const IF = lexbase.IF
View Source
const IFERROR = lexbase.IFERROR
View Source
const IFNULL = lexbase.IFNULL
View Source
const IGNORE_FOREIGN_KEYS = lexbase.IGNORE_FOREIGN_KEYS
View Source
const ILIKE = lexbase.ILIKE
View Source
const IMMEDIATE = lexbase.IMMEDIATE
View Source
const IMPORT = lexbase.IMPORT
View Source
const IN = lexbase.IN
View Source
const INCLUDE = lexbase.INCLUDE
View Source
const INCLUDING = lexbase.INCLUDING
View Source
const INCREMENT = lexbase.INCREMENT
View Source
const INCREMENTAL = lexbase.INCREMENTAL
View Source
const INCREMENTAL_LOCATION = lexbase.INCREMENTAL_LOCATION
View Source
const INDEX = lexbase.INDEX
View Source
const INDEXES = lexbase.INDEXES
View Source
const INET = lexbase.INET
View Source
const INET_CONTAINED_BY_OR_EQUALS = lexbase.INET_CONTAINED_BY_OR_EQUALS
View Source
const INET_CONTAINS_OR_EQUALS = lexbase.INET_CONTAINS_OR_EQUALS
View Source
const INHERITS = lexbase.INHERITS
View Source
const INITIALLY = lexbase.INITIALLY
View Source
const INJECT = lexbase.INJECT
View Source
const INNER = lexbase.INNER
View Source
const INSENSITIVE = lexbase.INSENSITIVE
View Source
const INSERT = lexbase.INSERT
View Source
const INT = lexbase.INT
View Source
const INTEGER = lexbase.INTEGER
View Source
const INTERSECT = lexbase.INTERSECT
View Source
const INTERVAL = lexbase.INTERVAL
View Source
const INTERVAL_SIMPLE = lexbase.INTERVAL_SIMPLE
View Source
const INTO = lexbase.INTO
View Source
const INTO_DB = lexbase.INTO_DB
View Source
const INVERTED = lexbase.INVERTED
View Source
const IS = lexbase.IS
View Source
const ISERROR = lexbase.ISERROR
View Source
const ISNULL = lexbase.ISNULL
View Source
const ISOLATION = lexbase.ISOLATION
View Source
const JOB = lexbase.JOB
View Source
const JOBS = lexbase.JOBS
View Source
const JOIN = lexbase.JOIN
View Source
const JSON = lexbase.JSON
View Source
const JSONB = lexbase.JSONB
View Source
const JSON_ALL_EXISTS = lexbase.JSON_ALL_EXISTS
View Source
const JSON_SOME_EXISTS = lexbase.JSON_SOME_EXISTS
View Source
const KEY = lexbase.KEY
View Source
const KEYS = lexbase.KEYS
View Source
const KMS = lexbase.KMS
View Source
const KV = lexbase.KV
View Source
const LANGUAGE = lexbase.LANGUAGE
View Source
const LAST = lexbase.LAST
View Source
const LATERAL = lexbase.LATERAL
View Source
const LATEST = lexbase.LATEST
View Source
const LC_COLLATE = lexbase.LC_COLLATE
View Source
const LC_CTYPE = lexbase.LC_CTYPE
View Source
const LEADING = lexbase.LEADING
View Source
const LEASE = lexbase.LEASE
View Source
const LEAST = lexbase.LEAST
View Source
const LEFT = lexbase.LEFT
View Source
const LESS = lexbase.LESS
View Source
const LESS_EQUALS = lexbase.LESS_EQUALS
View Source
const LEVEL = lexbase.LEVEL
View Source
const LIKE = lexbase.LIKE
View Source
const LIMIT = lexbase.LIMIT
View Source
const LINESTRING = lexbase.LINESTRING
View Source
const LINESTRINGM = lexbase.LINESTRINGM
View Source
const LINESTRINGZ = lexbase.LINESTRINGZ
View Source
const LINESTRINGZM = lexbase.LINESTRINGZM
View Source
const LIST = lexbase.LIST
View Source
const LOCAL = lexbase.LOCAL
View Source
const LOCALITY = lexbase.LOCALITY
View Source
const LOCALTIME = lexbase.LOCALTIME
View Source
const LOCALTIMESTAMP = lexbase.LOCALTIMESTAMP
View Source
const LOCKED = lexbase.LOCKED
View Source
const LOGIN = lexbase.LOGIN
View Source
const LOOKUP = lexbase.LOOKUP
View Source
const LOW = lexbase.LOW
View Source
const LSHIFT = lexbase.LSHIFT
View Source
const MATCH = lexbase.MATCH
View Source
const MATERIALIZED = lexbase.MATERIALIZED
View Source
const MAXVALUE = lexbase.MAXVALUE
View Source
const MERGE = lexbase.MERGE
View Source
const METHOD = lexbase.METHOD
View Source
const MINUTE = lexbase.MINUTE
View Source
const MINVALUE = lexbase.MINVALUE
View Source
const MODIFYCLUSTERSETTING = lexbase.MODIFYCLUSTERSETTING
View Source
const MONTH = lexbase.MONTH
View Source
const MOVE = lexbase.MOVE
View Source
const MULTILINESTRING = lexbase.MULTILINESTRING
View Source
const MULTILINESTRINGM = lexbase.MULTILINESTRINGM
View Source
const MULTILINESTRINGZ = lexbase.MULTILINESTRINGZ
View Source
const MULTILINESTRINGZM = lexbase.MULTILINESTRINGZM
View Source
const MULTIPOINT = lexbase.MULTIPOINT
View Source
const MULTIPOINTM = lexbase.MULTIPOINTM
View Source
const MULTIPOINTZ = lexbase.MULTIPOINTZ
View Source
const MULTIPOINTZM = lexbase.MULTIPOINTZM
View Source
const MULTIPOLYGON = lexbase.MULTIPOLYGON
View Source
const MULTIPOLYGONM = lexbase.MULTIPOLYGONM
View Source
const MULTIPOLYGONZ = lexbase.MULTIPOLYGONZ
View Source
const MULTIPOLYGONZM = lexbase.MULTIPOLYGONZM
View Source
const MaxInt = int(MaxUint >> 1)
View Source
const MaxUint = ^uint(0)
View Source
const NAME = lexbase.NAME
View Source
const NAMES = lexbase.NAMES
View Source
const NAN = lexbase.NAN
View Source
const NATURAL = lexbase.NATURAL
View Source
const NEVER = lexbase.NEVER
View Source
const NEW_DB_NAME = lexbase.NEW_DB_NAME
View Source
const NEW_KMS = lexbase.NEW_KMS
View Source
const NEXT = lexbase.NEXT
View Source
const NO = lexbase.NO
View Source
const NOCANCELQUERY = lexbase.NOCANCELQUERY
View Source
const NOCONTROLCHANGEFEED = lexbase.NOCONTROLCHANGEFEED
View Source
const NOCONTROLJOB = lexbase.NOCONTROLJOB
View Source
const NOCREATEDB = lexbase.NOCREATEDB
View Source
const NOCREATELOGIN = lexbase.NOCREATELOGIN
View Source
const NOCREATEROLE = lexbase.NOCREATEROLE
View Source
const NOLOGIN = lexbase.NOLOGIN
View Source
const NOMODIFYCLUSTERSETTING = lexbase.NOMODIFYCLUSTERSETTING
View Source
const NONE = lexbase.NONE
View Source
const NONVOTERS = lexbase.NONVOTERS
View Source
const NORMAL = lexbase.NORMAL
View Source
const NOSQLLOGIN = lexbase.NOSQLLOGIN
View Source
const NOT = lexbase.NOT
View Source
const NOTHING = lexbase.NOTHING
View Source
const NOTNULL = lexbase.NOTNULL
View Source
const NOT_EQUALS = lexbase.NOT_EQUALS
View Source
const NOT_LA = lexbase.NOT_LA
View Source
const NOT_REGIMATCH = lexbase.NOT_REGIMATCH
View Source
const NOT_REGMATCH = lexbase.NOT_REGMATCH
View Source
const NOVIEWACTIVITY = lexbase.NOVIEWACTIVITY
View Source
const NOVIEWACTIVITYREDACTED = lexbase.NOVIEWACTIVITYREDACTED
View Source
const NOVIEWCLUSTERSETTING = lexbase.NOVIEWCLUSTERSETTING
View Source
const NOWAIT = lexbase.NOWAIT
View Source
const NO_FULL_SCAN = lexbase.NO_FULL_SCAN
View Source
const NO_INDEX_JOIN = lexbase.NO_INDEX_JOIN
View Source
const NO_ZIGZAG_JOIN = lexbase.NO_ZIGZAG_JOIN
View Source
const NULL = lexbase.NULL
View Source
const NULLIF = lexbase.NULLIF
View Source
const NULLS = lexbase.NULLS
View Source
const NULLS_LA = lexbase.NULLS_LA
View Source
const NUMERIC = lexbase.NUMERIC
View Source
const OF = lexbase.OF
View Source
const OFF = lexbase.OFF
View Source
const OFFSET = lexbase.OFFSET
View Source
const OID = lexbase.OID
View Source
const OIDS = lexbase.OIDS
View Source
const OIDVECTOR = lexbase.OIDVECTOR
View Source
const OLD_KMS = lexbase.OLD_KMS
View Source
const ON = lexbase.ON
View Source
const ONLY = lexbase.ONLY
View Source
const ON_LA = lexbase.ON_LA
View Source
const OPERATOR = lexbase.OPERATOR
View Source
const OPT = lexbase.OPT
View Source
const OPTION = lexbase.OPTION
View Source
const OPTIONS = lexbase.OPTIONS
View Source
const OR = lexbase.OR
View Source
const ORDER = lexbase.ORDER
View Source
const ORDINALITY = lexbase.ORDINALITY
View Source
const OTHERS = lexbase.OTHERS
View Source
const OUT = lexbase.OUT
View Source
const OUTER = lexbase.OUTER
View Source
const OVER = lexbase.OVER
View Source
const OVERLAPS = lexbase.OVERLAPS
View Source
const OVERLAY = lexbase.OVERLAY
View Source
const OWNED = lexbase.OWNED
View Source
const OWNER = lexbase.OWNER
View Source
const PARENT = lexbase.PARENT
View Source
const PARTIAL = lexbase.PARTIAL
View Source
const PARTITION = lexbase.PARTITION
View Source
const PARTITIONS = lexbase.PARTITIONS
View Source
const PASSWORD = lexbase.PASSWORD
View Source
const PAUSE = lexbase.PAUSE
View Source
const PAUSED = lexbase.PAUSED
View Source
const PHYSICAL = lexbase.PHYSICAL
View Source
const PLACEHOLDER = lexbase.PLACEHOLDER
View Source
const PLACEMENT = lexbase.PLACEMENT
View Source
const PLACING = lexbase.PLACING
View Source
const PLAN = lexbase.PLAN
View Source
const PLANS = lexbase.PLANS
View Source
const POINT = lexbase.POINT
View Source
const POINTM = lexbase.POINTM
View Source
const POINTZ = lexbase.POINTZ
View Source
const POINTZM = lexbase.POINTZM
View Source
const POLYGON = lexbase.POLYGON
View Source
const POLYGONM = lexbase.POLYGONM
View Source
const POLYGONZ = lexbase.POLYGONZ
View Source
const POLYGONZM = lexbase.POLYGONZM
View Source
const POSITION = lexbase.POSITION
View Source
const POSTFIXOP = lexbase.POSTFIXOP
View Source
const PRECEDING = lexbase.PRECEDING
View Source
const PRECISION = lexbase.PRECISION
View Source
const PREPARE = lexbase.PREPARE
View Source
const PRESERVE = lexbase.PRESERVE
View Source
const PRIMARY = lexbase.PRIMARY
View Source
const PRIOR = lexbase.PRIOR
View Source
const PRIORITY = lexbase.PRIORITY
View Source
const PRIVILEGES = lexbase.PRIVILEGES
View Source
const PROCEDURAL = lexbase.PROCEDURAL
View Source
const PUBLIC = lexbase.PUBLIC
View Source
const PUBLICATION = lexbase.PUBLICATION
View Source
const QUERIES = lexbase.QUERIES
View Source
const QUERY = lexbase.QUERY
View Source
const RANGE = lexbase.RANGE
View Source
const RANGES = lexbase.RANGES
View Source
const READ = lexbase.READ
View Source
const REAL = lexbase.REAL
View Source
const REASON = lexbase.REASON
View Source
const REASSIGN = lexbase.REASSIGN
View Source
const RECURRING = lexbase.RECURRING
View Source
const RECURSIVE = lexbase.RECURSIVE
View Source
const REF = lexbase.REF
View Source
const REFERENCES = lexbase.REFERENCES
View Source
const REFRESH = lexbase.REFRESH
View Source
const REGCLASS = lexbase.REGCLASS
View Source
const REGIMATCH = lexbase.REGIMATCH
View Source
const REGION = lexbase.REGION
View Source
const REGIONAL = lexbase.REGIONAL
View Source
const REGIONS = lexbase.REGIONS
View Source
const REGNAMESPACE = lexbase.REGNAMESPACE
View Source
const REGPROC = lexbase.REGPROC
View Source
const REGPROCEDURE = lexbase.REGPROCEDURE
View Source
const REGROLE = lexbase.REGROLE
View Source
const REGTYPE = lexbase.REGTYPE
View Source
const REINDEX = lexbase.REINDEX
View Source
const RELATIVE = lexbase.RELATIVE
View Source
const RELEASE = lexbase.RELEASE
View Source
const RELOCATE = lexbase.RELOCATE
View Source
const REMOVE_PATH = lexbase.REMOVE_PATH
View Source
const RENAME = lexbase.RENAME
View Source
const REPEATABLE = lexbase.REPEATABLE
View Source
const REPLACE = lexbase.REPLACE
View Source
const REPLICATION = lexbase.REPLICATION
View Source
const RESET = lexbase.RESET
View Source
const RESET_ALL = lexbase.RESET_ALL
View Source
const RESTORE = lexbase.RESTORE
View Source
const RESTRICT = lexbase.RESTRICT
View Source
const RESTRICTED = lexbase.RESTRICTED
View Source
const RESUME = lexbase.RESUME
View Source
const RETRY = lexbase.RETRY
View Source
const RETURNING = lexbase.RETURNING
View Source
const REVISION_HISTORY = lexbase.REVISION_HISTORY
View Source
const REVOKE = lexbase.REVOKE
View Source
const RIGHT = lexbase.RIGHT
View Source
const ROLE = lexbase.ROLE
View Source
const ROLES = lexbase.ROLES
View Source
const ROLE_ALL = lexbase.ROLE_ALL
View Source
const ROLLBACK = lexbase.ROLLBACK
View Source
const ROLLUP = lexbase.ROLLUP
View Source
const ROUTINES = lexbase.ROUTINES
View Source
const ROW = lexbase.ROW
View Source
const ROWS = lexbase.ROWS
View Source
const RSHIFT = lexbase.RSHIFT
View Source
const RULE = lexbase.RULE
View Source
const RUNNING = lexbase.RUNNING
View Source
const SAVEPOINT = lexbase.SAVEPOINT
View Source
const SCANS = lexbase.SCANS
View Source
const SCATTER = lexbase.SCATTER
View Source
const SCHEDULE = lexbase.SCHEDULE
View Source
const SCHEDULES = lexbase.SCHEDULES
View Source
const SCHEMA = lexbase.SCHEMA
View Source
const SCHEMAS = lexbase.SCHEMAS
View Source
const SCONST = lexbase.SCONST
View Source
const SCROLL = lexbase.SCROLL
View Source
const SCRUB = lexbase.SCRUB
View Source
const SEARCH = lexbase.SEARCH
View Source
const SECOND = lexbase.SECOND
View Source
const SELECT = lexbase.SELECT
View Source
const SEQUENCE = lexbase.SEQUENCE
View Source
const SEQUENCES = lexbase.SEQUENCES
View Source
const SERIALIZABLE = lexbase.SERIALIZABLE
View Source
const SERVER = lexbase.SERVER
View Source
const SESSION = lexbase.SESSION
View Source
const SESSIONS = lexbase.SESSIONS
View Source
const SESSION_USER = lexbase.SESSION_USER
View Source
const SET = lexbase.SET
View Source
const SETS = lexbase.SETS
View Source
const SETTING = lexbase.SETTING
View Source
const SETTINGS = lexbase.SETTINGS
View Source
const SHARE = lexbase.SHARE
View Source
const SHOW = lexbase.SHOW
View Source
const SIMILAR = lexbase.SIMILAR
View Source
const SIMPLE = lexbase.SIMPLE
View Source
const SKIP = lexbase.SKIP
View Source
const SKIP_LOCALITIES_CHECK = lexbase.SKIP_LOCALITIES_CHECK
View Source
const SKIP_MISSING_FOREIGN_KEYS = lexbase.SKIP_MISSING_FOREIGN_KEYS
View Source
const SKIP_MISSING_SEQUENCES = lexbase.SKIP_MISSING_SEQUENCES
View Source
const SKIP_MISSING_SEQUENCE_OWNERS = lexbase.SKIP_MISSING_SEQUENCE_OWNERS
View Source
const SKIP_MISSING_VIEWS = lexbase.SKIP_MISSING_VIEWS
View Source
const SMALLINT = lexbase.SMALLINT
View Source
const SMALLSERIAL = lexbase.SMALLSERIAL
View Source
const SNAPSHOT = lexbase.SNAPSHOT
View Source
const SOME = lexbase.SOME
View Source
const SPLIT = lexbase.SPLIT
View Source
const SQL = lexbase.SQL
View Source
const SQLLOGIN = lexbase.SQLLOGIN
View Source
const SQRT = lexbase.SQRT
View Source
const START = lexbase.START
View Source
const STATE = lexbase.STATE
View Source
const STATEMENTS = lexbase.STATEMENTS
View Source
const STATISTICS = lexbase.STATISTICS
View Source
const STATUS = lexbase.STATUS
View Source
const STDIN = lexbase.STDIN
View Source
const STORAGE = lexbase.STORAGE
View Source
const STORE = lexbase.STORE
View Source
const STORED = lexbase.STORED
View Source
const STORING = lexbase.STORING
View Source
const STREAM = lexbase.STREAM
View Source
const STRICT = lexbase.STRICT
View Source
const STRING = lexbase.STRING
View Source
const SUBSCRIPTION = lexbase.SUBSCRIPTION
View Source
const SUBSTRING = lexbase.SUBSTRING
View Source
const SUPER = lexbase.SUPER
View Source
const SURVIVAL = lexbase.SURVIVAL
View Source
const SURVIVE = lexbase.SURVIVE
View Source
const SYMMETRIC = lexbase.SYMMETRIC
View Source
const SYNTAX = lexbase.SYNTAX
View Source
const SYSTEM = lexbase.SYSTEM
View Source
const TABLE = lexbase.TABLE
View Source
const TABLES = lexbase.TABLES
View Source
const TABLESPACE = lexbase.TABLESPACE
View Source
const TEMP = lexbase.TEMP
View Source
const TEMPLATE = lexbase.TEMPLATE
View Source
const TEMPORARY = lexbase.TEMPORARY
View Source
const TENANT = lexbase.TENANT
View Source
const TENANTS = lexbase.TENANTS
View Source
const TENANT_ALL = lexbase.TENANT_ALL
View Source
const TESTING_RELOCATE = lexbase.TESTING_RELOCATE
View Source
const TEXT = lexbase.TEXT
View Source
const THEN = lexbase.THEN
View Source
const THROTTLING = lexbase.THROTTLING
View Source
const TIES = lexbase.TIES
View Source
const TIME = lexbase.TIME
View Source
const TIMESTAMP = lexbase.TIMESTAMP
View Source
const TIMESTAMPTZ = lexbase.TIMESTAMPTZ
View Source
const TIMETZ = lexbase.TIMETZ
View Source
const TO = lexbase.TO
View Source
const TRACE = lexbase.TRACE
View Source
const TRACING = lexbase.TRACING
View Source
const TRAILING = lexbase.TRAILING
View Source
const TRANSACTION = lexbase.TRANSACTION
View Source
const TRANSACTIONS = lexbase.TRANSACTIONS
View Source
const TRANSFER = lexbase.TRANSFER
View Source
const TREAT = lexbase.TREAT
View Source
const TRIGGER = lexbase.TRIGGER
View Source
const TRIM = lexbase.TRIM
View Source
const TRUE = lexbase.TRUE
View Source
const TRUNCATE = lexbase.TRUNCATE
View Source
const TRUSTED = lexbase.TRUSTED
View Source
const TYPE = lexbase.TYPE
View Source
const TYPEANNOTATE = lexbase.TYPEANNOTATE
View Source
const TYPECAST = lexbase.TYPECAST
View Source
const TYPES = lexbase.TYPES
View Source
const UMINUS = lexbase.UMINUS
View Source
const UNBOUNDED = lexbase.UNBOUNDED
View Source
const UNCOMMITTED = lexbase.UNCOMMITTED
View Source
const UNION = lexbase.UNION
View Source
const UNIQUE = lexbase.UNIQUE
View Source
const UNKNOWN = lexbase.UNKNOWN
View Source
const UNLOGGED = lexbase.UNLOGGED
View Source
const UNSET = lexbase.UNSET
View Source
const UNSPLIT = lexbase.UNSPLIT
View Source
const UNTIL = lexbase.UNTIL
View Source
const UPDATE = lexbase.UPDATE
View Source
const UPSERT = lexbase.UPSERT
View Source
const USE = lexbase.USE
View Source
const USER = lexbase.USER
View Source
const USERS = lexbase.USERS
View Source
const USER_ALL = lexbase.USER_ALL
View Source
const USING = lexbase.USING
View Source
const UUID = lexbase.UUID
View Source
const VALID = lexbase.VALID
View Source
const VALIDATE = lexbase.VALIDATE
View Source
const VALUE = lexbase.VALUE
View Source
const VALUES = lexbase.VALUES
View Source
const VARBIT = lexbase.VARBIT
View Source
const VARCHAR = lexbase.VARCHAR
View Source
const VARIADIC = lexbase.VARIADIC
View Source
const VARYING = lexbase.VARYING
View Source
const VIEW = lexbase.VIEW
View Source
const VIEWACTIVITY = lexbase.VIEWACTIVITY
View Source
const VIEWACTIVITYREDACTED = lexbase.VIEWACTIVITYREDACTED
View Source
const VIEWCLUSTERSETTING = lexbase.VIEWCLUSTERSETTING
View Source
const VIRTUAL = lexbase.VIRTUAL
View Source
const VISIBLE = lexbase.VISIBLE
View Source
const VOTERS = lexbase.VOTERS
View Source
const WHEN = lexbase.WHEN
View Source
const WHERE = lexbase.WHERE
View Source
const WINDOW = lexbase.WINDOW
View Source
const WITH = lexbase.WITH
View Source
const WITHIN = lexbase.WITHIN
View Source
const WITHOUT = lexbase.WITHOUT
View Source
const WITH_LA = lexbase.WITH_LA
View Source
const WORK = lexbase.WORK
View Source
const WRITE = lexbase.WRITE
View Source
const YEAR = lexbase.YEAR
View Source
const ZONE = lexbase.ZONE

Variables

View Source
var AllHelp = func(h map[string]HelpMessageBody) string {

	cmds := make(map[string][]string)
	for c, details := range h {
		if details.Category == "" {
			continue
		}
		cmds[details.Category] = append(cmds[details.Category], c)
	}

	// Ensure the result is deterministic.
	var categories []string
	for c, l := range cmds {
		categories = append(categories, c)
		sort.Strings(l)
	}
	sort.Strings(categories)

	// Compile the final help index.
	var buf bytes.Buffer
	w := tabwriter.NewWriter(&buf, 0, 0, 1, ' ', 0)
	for _, cat := range categories {
		fmt.Fprintf(w, "%s:\n", strings.Title(cat))
		for _, item := range cmds[cat] {
			fmt.Fprintf(w, "\t\t%s\t%s\n", item, h[item].ShortDescription)
		}
		fmt.Fprintln(w)
	}
	_ = w.Flush()
	return buf.String()
}(helpMessages)

AllHelp contains an overview of all statements with help messages. For example, displayed in the CLI shell with \h without additional parameters.

View Source
var HelpMessages = func(h map[string]HelpMessageBody) map[string]HelpMessageBody {
	appendSeeAlso := func(newItem, prevItems string) string {

		if prevItems != "" {
			return newItem + "\n  " + prevItems
		}
		return newItem
	}
	reformatSeeAlso := func(seeAlso string) string {
		return strings.Replace(
			strings.Replace(seeAlso, ", ", "\n  ", -1),
			"WEBDOCS", "", -1)
	}
	srcMsg := h["<SOURCE>"]
	srcMsg.SeeAlso = reformatSeeAlso(strings.TrimSpace(srcMsg.SeeAlso))
	selectMsg := h["<SELECTCLAUSE>"]
	selectMsg.SeeAlso = reformatSeeAlso(strings.TrimSpace(selectMsg.SeeAlso))
	for k, m := range h {
		m = h[k]
		m.ShortDescription = strings.TrimSpace(m.ShortDescription)
		m.Text = strings.TrimSpace(m.Text)
		m.SeeAlso = strings.TrimSpace(m.SeeAlso)

		if strings.Contains(m.Text, "<source>") && k != "<SOURCE>" {
			m.Text = strings.TrimSpace(m.Text) + "\n\n" + strings.TrimSpace(srcMsg.Text)
			m.SeeAlso = appendSeeAlso(srcMsg.SeeAlso, m.SeeAlso)
		}

		if strings.Contains(m.Text, "<selectclause>") && k != "<SELECTCLAUSE>" {
			m.Text = strings.TrimSpace(m.Text) + "\n\n" + strings.TrimSpace(selectMsg.Text)
			m.SeeAlso = appendSeeAlso(selectMsg.SeeAlso, m.SeeAlso)
		}

		if strings.Contains(m.Text, "<tablename>") {
			m.SeeAlso = appendSeeAlso("SHOW TABLES", m.SeeAlso)
		}
		m.SeeAlso = reformatSeeAlso(m.SeeAlso)
		h[k] = m
	}
	return h
}(helpMessages)

HelpMessages is the registry of all help messages, keyed by the top-level statement that they document. The key is intended for use via the \h client-side command.

Functions

func GetTypeFromValidSQLSyntax

func GetTypeFromValidSQLSyntax(sql string) (tree.ResolvableTypeReference, error)

GetTypeFromValidSQLSyntax retrieves a type from its SQL syntax. The caller is responsible for guaranteeing that the type expression is valid SQL. This includes verifying that complex identifiers are enclosed in double quotes, etc.

func GetTypeReferenceFromName

func GetTypeReferenceFromName(typeName tree.Name) (tree.ResolvableTypeReference, error)

GetTypeReferenceFromName turns a type name into a type reference. This supports only “simple” (single-identifier) references to built-in types, when the identifer has already been parsed away from the input SQL syntax.

func NakedIntTypeFromDefaultIntSize

func NakedIntTypeFromDefaultIntSize(defaultIntSize int32) *types.T

NakedIntTypeFromDefaultIntSize given the size in bits or bytes (preferred) of how a "naked" INT type should be parsed returns the corresponding integer type.

func ParseExpr

func ParseExpr(sql string) (tree.Expr, error)

ParseExpr parses a SQL scalar expression. The caller is responsible for ensuring that the input is, in fact, a valid SQL scalar expression — the results are undefined if the string contains invalid SQL syntax.

func ParseExprWithInt

func ParseExprWithInt(sql string, nakedIntType *types.T) (tree.Expr, error)

ParseExprWithInt parses a SQL scalar expression, using the given type when INT is used as type name in the SQL syntax. The caller is responsible for ensuring that the input is, in fact, a valid SQL scalar expression — the results are undefined if the string contains invalid SQL syntax.

func ParseExprs

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

ParseExprs parses a comma-delimited sequence of SQL scalar expressions. The caller is responsible for ensuring that the input is, in fact, a comma-delimited sequence of SQL scalar expressions — the results are undefined if the string contains invalid SQL syntax.

func ParseQualifiedTableName

func ParseQualifiedTableName(sql string) (*tree.TableName, error)

ParseQualifiedTableName parses a possibly qualified table name. The table name must contain one or more name parts, using the full input SQL syntax: each name part containing special characters, or non-lowercase characters, must be enclosed in double quote. The name may not be an invalid table name (the caller is responsible for guaranteeing that only valid table names are provided as input).

func ParseTableName

func ParseTableName(sql string) (*tree.UnresolvedObjectName, error)

ParseTableName parses a table name. The table name must contain one or more name parts, using the full input SQL syntax: each name part containing special characters, or non-lowercase characters, must be enclosed in double quote. The name may not be an invalid table name (the caller is responsible for guaranteeing that only valid table names are provided as input).

func RunShowSyntax

func RunShowSyntax(
	ctx context.Context,
	stmt string,
	report func(ctx context.Context, field, msg string),
	reportErr func(ctx context.Context, err error),
)

RunShowSyntax analyzes the syntax and reports its structure as data for the client. Even an error is reported as data.

Since errors won't propagate to the client as an error, but as a result, the usual code path to capture and record errors will not be triggered. Instead, the caller can pass a reportErr closure to capture errors instead. May be nil.

func SplitFirstStatement

func SplitFirstStatement(sql string) (pos int, ok bool)

SplitFirstStatement returns the length of the prefix of the string up to and including the first semicolon that separates statements. If there is no including the first semicolon that separates statements. If there is no semicolon, returns ok=false.

Types

type HelpMessage

type HelpMessage struct {
	// Command is set if the message is about a statement.
	Command string
	// Function is set if the message is about a built-in function.
	Function string

	// HelpMessageBody contains the details of the message.
	HelpMessageBody
}

HelpMessage describes a contextual help message.

func (*HelpMessage) Format

func (h *HelpMessage) Format(w io.Writer)

Format prints out details about the message onto the specified output stream.

func (*HelpMessage) String

func (h *HelpMessage) String() string

String implements the fmt.String interface.

type HelpMessageBody

type HelpMessageBody struct {
	Category         string
	ShortDescription string
	Text             string
	SeeAlso          string
}

HelpMessageBody defines the body of a help text. The messages are structured to facilitate future help navigation functionality.

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

func (p *Parser) Parse(sql string) (Statements, error)

Parse parses the sql and returns a list of statements.

func (*Parser) ParseWithInt

func (p *Parser) ParseWithInt(sql string, nakedIntType *types.T) (Statements, error)

ParseWithInt parses a sql statement string and returns a list of Statements. The INT token will result in the specified TInt type.

type Statement

type Statement struct {
	// AST is the root of the AST tree for the parsed statement.
	AST tree.Statement

	// SQL is the original SQL from which the statement was parsed. Note that this
	// is not appropriate for use in logging, as it may contain passwords and
	// other sensitive data.
	SQL string

	// NumPlaceholders indicates the number of arguments to the statement (which
	// are referenced through placeholders). This corresponds to the highest
	// argument position (i.e. the x in "$x") that appears in the query.
	//
	// Note: where there are "gaps" in the placeholder positions, this number is
	// based on the highest position encountered. For example, for `SELECT $3`,
	// NumPlaceholders is 3. These cases are malformed and will result in a
	// type-check error.
	NumPlaceholders int

	// NumAnnotations indicates the number of annotations in the tree. It is equal
	// to the maximum annotation index.
	NumAnnotations tree.AnnotationIdx
}

Statement is the result of parsing a single statement. It contains the AST node along with other information.

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. ParseOne will always interpret the INT and SERIAL types as 64-bit types, since this is used in various internal-execution paths where we might receive bits of SQL from other nodes. In general,earwe expect that all user-generated SQL has been run through the ParseWithInt() function.

func ParseOneWithInt

func ParseOneWithInt(sql string, nakedIntType *types.T) (Statement, error)

ParseOneWithInt is similar to ParseOn but interprets the INT and SERIAL types as the provided integer type.

type Statements

type Statements []Statement

Statements is a list of parsed statements.

func Parse

func Parse(sql string) (Statements, error)

Parse parses a sql statement string and returns a list of Statements.

func (Statements) String

func (stmts Statements) String() string

String returns the AST formatted as a string.

func (Statements) StringWithFlags

func (stmts Statements) StringWithFlags(flags tree.FmtFlags) string

StringWithFlags returns the AST formatted as a string (with the given flags).

type TokenString

type TokenString struct {
	TokenID int32
	Str     string
}

TokenString is the unit value returned by Tokens.

func Tokens

func Tokens(sql string) (tokens []TokenString, ok bool)

Tokens decomposes the input into lexical tokens.

func TokensIgnoreErrors

func TokensIgnoreErrors(sql string) (tokens []TokenString)

TokensIgnoreErrors decomposes the input into lexical tokens and ignores errors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL