parser

package
v0.25.2 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2025 License: Apache-2.0 Imports: 31 Imported by: 11

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

Overview

Package parser contains exposes a SQL parser for cockroach.

Index

Constants

View Source
const ABORT = 57363
View Source
const ABSOLUTE = 57364
View Source
const ACCESS = 57365
View Source
const ACTION = 57366
View Source
const ADD = 57367
View Source
const ADMIN = 57368
View Source
const AFTER = 57369
View Source
const AGGREGATE = 57370
View Source
const ALL = 57371
View Source
const ALTER = 57372
View Source
const ALWAYS = 57373
View Source
const ANALYSE = 57374
View Source
const ANALYZE = 57375
View Source
const AND = 57376
View Source
const AND_AND = 57377
View Source
const ANNOTATE_TYPE = 57379
View Source
const ANY = 57378
View Source
const ARRAY = 57380
View Source
const AS = 57381
View Source
const ASC = 57382
View Source
const ASENSITIVE = 57385
View Source
const ASYMMETRIC = 57386
View Source
const AS_JSON = 57383
View Source
const AS_LA = 58051
View Source
const AT = 57387
View Source
const ATOMIC = 57388
View Source
const ATTRIBUTE = 57389
View Source
const AT_AT = 57384
View Source
const AUTHORIZATION = 57390
View Source
const AUTOMATIC = 57391
View Source
const AVAILABILITY = 57392
View Source
const AVOID_FULL_SCAN = 57393
View Source
const BACKUP = 57394
View Source
const BACKUPS = 57395
View Source
const BACKWARD = 57396
View Source
const BATCH = 57397
View Source
const BCONST = 57348
View Source
const BEFORE = 57398
View Source
const BEGIN = 57399
View Source
const BETWEEN = 57400
View Source
const BIDIRECTIONAL = 57401
View Source
const BIGINT = 57402
View Source
const BIGSERIAL = 57403
View Source
const BINARY = 57404
View Source
const BIT = 57405
View Source
const BITCONST = 57349
View Source
const BOOLEAN = 57407
View Source
const BOTH = 57408
View Source
const BOX2D = 57409
View Source
const BUCKET_COUNT = 57406
View Source
const BUNDLE = 57410
View Source
const BY = 57411
View Source
const BYPASSRLS = 57412
View Source
const CACHE = 57413
View Source
const CALL = 57414
View Source
const CALLED = 57415
View Source
const CANCEL = 57416
View Source
const CANCELQUERY = 57417
View Source
const CAPABILITIES = 57418
View Source
const CAPABILITY = 57419
View Source
const CASCADE = 57420
View Source
const CASE = 57421
View Source
const CAST = 57422
View Source
const CBRT = 57423
View Source
const CHANGEFEED = 57424
View Source
const CHAR = 57425
View Source
const CHARACTER = 57426
View Source
const CHARACTERISTICS = 57427
View Source
const CHECK = 57428
View Source
const CHECK_FILES = 57429
View Source
const CLOSE = 57430
View Source
const CLUSTER = 57431
View Source
const CLUSTERS = 57432
View Source
const CLUSTER_ALL = 58059
View Source
const COALESCE = 57433
View Source
const COLLATE = 57434
View Source
const COLLATION = 57435
View Source
const COLUMN = 57436
View Source
const COLUMNS = 57437
View Source
const COMMENT = 57438
View Source
const COMMENTS = 57439
View Source
const COMMIT = 57440
View Source
const COMMITTED = 57441
View Source
const COMPACT = 57442
View Source
const COMPLETE = 57443
View Source
const COMPLETIONS = 57444
View Source
const CONCAT = 57445
View Source
const CONCURRENTLY = 57446
View Source
const CONFIGURATION = 57447
View Source
const CONFIGURATIONS = 57448
View Source
const CONFIGURE = 57449
View Source
const CONFLICT = 57450
View Source
const CONNECTION = 57451
View Source
const CONNECTIONS = 57452
View Source
const CONSTRAINT = 57453
View Source
const CONSTRAINTS = 57454
View Source
const CONTAINED_BY = 58061
View Source
const CONTAINS = 57455
View Source
const CONTROLCHANGEFEED = 57456
View Source
const CONTROLJOB = 57457
View Source
const CONVERSION = 57458
View Source
const CONVERT = 57459
View Source
const COPY = 57460
View Source
const COST = 57462
View Source
const COS_DISTANCE = 57461
View Source
const COVERING = 57463
View Source
const CREATE = 57464
View Source
const CREATEDB = 57465
View Source
const CREATELOGIN = 57466
View Source
const CREATEROLE = 57467
View Source
const CROSS = 57468
View Source
const CSV = 57469
View Source
const CUBE = 57470
View Source
const CURRENT = 57471
View Source
const CURRENT_CATALOG = 57472
View Source
const CURRENT_DATE = 57473
View Source
const CURRENT_ROLE = 57475
View Source
const CURRENT_SCHEMA = 57474
View Source
const CURRENT_TIME = 57476
View Source
const CURRENT_TIMESTAMP = 57477
View Source
const CURRENT_USER = 57478
View Source
const CURSOR = 57479
View Source
const CYCLE = 57480
View Source
const DATA = 57481
View Source
const DATABASE = 57482
View Source
const DATABASES = 57483
View Source
const DATE = 57484
View Source
const DAY = 57485
View Source
const DEALLOCATE = 57492
View Source
const DEBUG_IDS = 57486
View Source
const DEC = 57487
View Source
const DECIMAL = 57488
View Source
const DECLARE = 57493
View Source
const DEFAULT = 57489
View Source
const DEFAULTS = 57490
View Source
const DEFERRABLE = 57494
View Source
const DEFERRED = 57495
View Source
const DEFINER = 57491
View Source
const DELETE = 57496
View Source
const DELIMITER = 57497
View Source
const DEPENDS = 57498
View Source
const DESC = 57499
View Source
const DESTINATION = 57500
View Source
const DETACHED = 57501
View Source
const DETAILS = 57502
View Source
const DISABLE = 57503
View Source
const DISCARD = 57504
View Source
const DISTANCE = 57505
View Source
const DISTINCT = 57506
View Source
const DO = 57507
View Source
const DOMAIN = 57508
View Source
const DOT_DOT = 57355
View Source
const DOUBLE = 57509
View Source
const DROP = 57510
View Source
const EACH = 57511
View Source
const ELSE = 57512
View Source
const ENABLE = 57513
View Source
const ENCODING = 57514
View Source
const ENCRYPTED = 57515
View Source
const ENCRYPTION_INFO_DIR = 57516
View Source
const ENCRYPTION_PASSPHRASE = 57517
View Source
const END = 57518
View Source
const ENUM = 57519
View Source
const ENUMS = 57520
View Source
const ERROR = 57362
View Source
const ESCAPE = 57521
View Source
const EXCEPT = 57522
View Source
const EXCLUDE = 57523
View Source
const EXCLUDING = 57524
View Source
const EXECUTE = 57526
View Source
const EXECUTION = 57527
View Source
const EXISTS = 57525
View Source
const EXPERIMENTAL = 57528
View Source
const EXPERIMENTAL_AUDIT = 57531
View Source
const EXPERIMENTAL_FINGERPRINTS = 57529
View Source
const EXPERIMENTAL_RELOCATE = 57532
View Source
const EXPERIMENTAL_REPLICA = 57530
View Source
const EXPIRATION = 57533
View Source
const EXPLAIN = 57534
View Source
const EXPORT = 57535
View Source
const EXTENSION = 57536
View Source
const EXTERNAL = 57537
View Source
const EXTRACT = 57538
View Source
const EXTRACT_DURATION = 57539
View Source
const EXTREMES = 57540
View Source
const FAILURE = 57541
View Source
const FALSE = 57542
View Source
const FAMILY = 57543
View Source
const FCONST = 57351
View Source
const FETCH = 57544
View Source
const FETCHTEXT = 57546
View Source
const FETCHTEXT_PATH = 57548
View Source
const FETCHVAL = 57545
View Source
const FETCHVAL_PATH = 57547
View Source
const FILES = 57549
View Source
const FILTER = 57550
View Source
const FIRST = 57551
View Source
const FLOAT = 57552
View Source
const FLOAT4 = 57553
View Source
const FLOAT8 = 57554
View Source
const FLOORDIV = 57555
View Source
const FOLLOWING = 57556
View Source
const FOR = 57557
View Source
const FORCE = 57558
View Source
const FORCE_INDEX = 57559
View Source
const FORCE_INVERTED_INDEX = 57560
View Source
const FORCE_NOT_NULL = 57561
View Source
const FORCE_NULL = 57562
View Source
const FORCE_QUOTE = 57563
View Source
const FORCE_ZIGZAG = 57564
View Source
const FOREIGN = 57565
View Source
const FORMAT = 57566
View Source
const FORWARD = 57567
View Source
const FREEZE = 57568
View Source
const FROM = 57569
View Source
const FULL = 57570
View Source
const FUNCTION = 57571
View Source
const FUNCTIONS = 57572
View Source
const GENERATED = 57573
View Source
const GENERATED_ALWAYS = 58052
View Source
const GENERATED_BY_DEFAULT = 58053
View Source
const GEOGRAPHY = 57574
View Source
const GEOMETRY = 57575
View Source
const GEOMETRYCOLLECTION = 57579
View Source
const GEOMETRYCOLLECTIONM = 57580
View Source
const GEOMETRYCOLLECTIONZ = 57581
View Source
const GEOMETRYCOLLECTIONZM = 57582
View Source
const GEOMETRYM = 57576
View Source
const GEOMETRYZ = 57577
View Source
const GEOMETRYZM = 57578
View Source
const GLOBAL = 57583
View Source
const GOAL = 57584
View Source
const GRANT = 57585
View Source
const GRANTEE = 57586
View Source
const GRANTS = 57587
View Source
const GREATER_EQUALS = 57357
View Source
const GREATEST = 57588
View Source
const GROUP = 57589
View Source
const GROUPING = 57590
View Source
const GROUPS = 57591
View Source
const HASH = 57593
View Source
const HAVING = 57592
View Source
const HEADER = 57594
View Source
const HELPTOKEN = 58065
View Source
const HIGH = 57595
View Source
const HISTOGRAM = 57596
View Source
const HOLD = 57597
View Source
const HOUR = 57598
View Source
const ICONST = 57350
View Source
const IDENT = 57346
View Source
const IDENTITY = 57599
View Source
const IF = 57600
View Source
const IFERROR = 57601
View Source
const IFNULL = 57602
View Source
const IGNORE_FOREIGN_KEYS = 57603
View Source
const ILIKE = 57604
View Source
const IMMEDIATE = 57605
View Source
const IMMEDIATELY = 57606
View Source
const IMMUTABLE = 57607
View Source
const IMPORT = 57608
View Source
const IN = 57609
View Source
const INCLUDE = 57610
View Source
const INCLUDE_ALL_SECONDARY_TENANTS = 57612
View Source
const INCLUDE_ALL_VIRTUAL_CLUSTERS = 57613
View Source
const INCLUDING = 57611
View Source
const INCREMENT = 57614
View Source
const INCREMENTAL = 57615
View Source
const INCREMENTAL_LOCATION = 57616
View Source
const INDEX = 57620
View Source
const INDEXES = 57621
View Source
const INDEX_AFTER_ORDER_BY_BEFORE_AT = 57627
View Source
const INDEX_BEFORE_NAME_THEN_PAREN = 57626
View Source
const INDEX_BEFORE_PAREN = 57625
View Source
const INET = 57617
View Source
const INET_CONTAINED_BY_OR_EQUALS = 57618
View Source
const INET_CONTAINS_OR_EQUALS = 57619
View Source
const INHERITS = 57622
View Source
const INITIALLY = 57624
View Source
const INJECT = 57623
View Source
const INNER = 57628
View Source
const INOUT = 57629
View Source
const INPUT = 57630
View Source
const INSENSITIVE = 57631
View Source
const INSERT = 57632
View Source
const INSTEAD = 57633
View Source
const INT = 57634
View Source
const INTEGER = 57635
View Source
const INTERSECT = 57636
View Source
const INTERVAL = 57637
View Source
const INTERVAL_SIMPLE = 58063
View Source
const INTO = 57638
View Source
const INTO_DB = 57639
View Source
const INVERTED = 57640
View Source
const INVISIBLE = 58032
View Source
const INVOKER = 57641
View Source
const IS = 57642
View Source
const ISERROR = 57643
View Source
const ISNULL = 57644
View Source
const ISOLATION = 57645
View Source
const JOB = 57646
View Source
const JOBS = 57647
View Source
const JOIN = 57648
View Source
const JSON = 57649
View Source
const JSONB = 57650
View Source
const JSON_ALL_EXISTS = 57652
View Source
const JSON_SOME_EXISTS = 57651
View Source
const KEY = 57653
View Source
const KEYS = 57654
View Source
const KMS = 57655
View Source
const KV = 57656
View Source
const LABEL = 57657
View Source
const LANGUAGE = 57658
View Source
const LAST = 57659
View Source
const LATERAL = 57660
View Source
const LATEST = 57661
View Source
const LC_COLLATE = 57663
View Source
const LC_CTYPE = 57662
View Source
const LEADING = 57664
View Source
const LEAKPROOF = 57667
View Source
const LEASE = 57665
View Source
const LEAST = 57666
View Source
const LEFT = 57668
View Source
const LESS = 57669
View Source
const LESS_EQUALS = 57356
View Source
const LEVEL = 57670
View Source
const LIKE = 57671
View Source
const LIMIT = 57672
View Source
const LINESTRING = 57673
View Source
const LINESTRINGM = 57674
View Source
const LINESTRINGZ = 57675
View Source
const LINESTRINGZM = 57676
View Source
const LIST = 57677
View Source
const LOCAL = 57678
View Source
const LOCALITY = 57679
View Source
const LOCALTIME = 57680
View Source
const LOCALTIMESTAMP = 57681
View Source
const LOCKED = 57682
View Source
const LOGICAL = 57683
View Source
const LOGICALLY = 57684
View Source
const LOGIN = 57685
View Source
const LOOKUP = 57686
View Source
const LOW = 57687
View Source
const LSHIFT = 57688
View Source
const MATCH = 57689
View Source
const MATERIALIZED = 57690
View Source
const MAXVALUE = 57693
View Source
const MERGE = 57691
View Source
const METHOD = 57694
View Source
const MINUTE = 57695
View Source
const MINVALUE = 57692
View Source
const MODE = 57698
View Source
const MODIFYCLUSTERSETTING = 57696
View Source
const MODIFYSQLCLUSTERSETTING = 57697
View Source
const MONTH = 57699
View Source
const MOVE = 57700
View Source
const MULTILINESTRING = 57701
View Source
const MULTILINESTRINGM = 57702
View Source
const MULTILINESTRINGZ = 57703
View Source
const MULTILINESTRINGZM = 57704
View Source
const MULTIPOINT = 57705
View Source
const MULTIPOINTM = 57706
View Source
const MULTIPOINTZ = 57707
View Source
const MULTIPOINTZM = 57708
View Source
const MULTIPOLYGON = 57709
View Source
const MULTIPOLYGONM = 57710
View Source
const MULTIPOLYGONZ = 57711
View Source
const MULTIPOLYGONZM = 57712
View Source
const MaxInt = int(MaxUint >> 1)
View Source
const MaxUint = ^uint(0)
View Source
const NAME = 57714
View Source
const NAMES = 57715
View Source
const NAN = 57713
View Source
const NATURAL = 57716
View Source
const NEG_INNER_PRODUCT = 57717
View Source
const NEVER = 57718
View Source
const NEW = 57719
View Source
const NEW_DB_NAME = 57720
View Source
const NEW_KMS = 57721
View Source
const NEXT = 57722
View Source
const NO = 57723
View Source
const NOBYPASSRLS = 57724
View Source
const NOCANCELQUERY = 57725
View Source
const NOCONTROLCHANGEFEED = 57726
View Source
const NOCONTROLJOB = 57727
View Source
const NOCREATEDB = 57728
View Source
const NOCREATELOGIN = 57729
View Source
const NOCREATEROLE = 57730
View Source
const NODE = 57731
View Source
const NOLOGIN = 57732
View Source
const NOMODIFYCLUSTERSETTING = 57733
View Source
const NONE = 57739
View Source
const NONVOTERS = 57740
View Source
const NOREPLICATION = 57734
View Source
const NORMAL = 57741
View Source
const NOSQLLOGIN = 57735
View Source
const NOT = 57742
View Source
const NOTHING = 57743
View Source
const NOTHING_AFTER_RETURNING = 57744
View Source
const NOTNULL = 57745
View Source
const NOT_EQUALS = 57358
View Source
const NOT_LA = 58048
View Source
const NOT_REGIMATCH = 57361
View Source
const NOT_REGMATCH = 57359
View Source
const NOVIEWACTIVITY = 57746
View Source
const NOVIEWACTIVITYREDACTED = 57747
View Source
const NOVIEWCLUSTERSETTING = 57748
View Source
const NOWAIT = 57749
View Source
const NO_FULL_SCAN = 57738
View Source
const NO_INDEX_JOIN = 57736
View Source
const NO_ZIGZAG_JOIN = 57737
View Source
const NULL = 57750
View Source
const NULLIF = 57751
View Source
const NULLS = 57752
View Source
const NULLS_LA = 58049
View Source
const NUMERIC = 57753
View Source
const OF = 57754
View Source
const OFF = 57755
View Source
const OFFSET = 57756
View Source
const OID = 57757
View Source
const OIDS = 57758
View Source
const OIDVECTOR = 57759
View Source
const OLD = 57760
View Source
const OLD_KMS = 57761
View Source
const ON = 57762
View Source
const ONLY = 57763
View Source
const ON_LA = 58057
View Source
const OPERATOR = 57778
View Source
const OPT = 57764
View Source
const OPTION = 57765
View Source
const OPTIONS = 57766
View Source
const OR = 57767
View Source
const ORDER = 57768
View Source
const ORDINALITY = 57769
View Source
const OTHERS = 57770
View Source
const OUT = 57771
View Source
const OUTER = 57772
View Source
const OVER = 57773
View Source
const OVERLAPS = 57774
View Source
const OVERLAY = 57775
View Source
const OWNED = 57776
View Source
const OWNER = 57777
View Source
const PARALLEL = 57779
View Source
const PARENT = 57780
View Source
const PARTIAL = 57781
View Source
const PARTITION = 57782
View Source
const PARTITIONS = 57783
View Source
const PASSWORD = 57784
View Source
const PAUSE = 57785
View Source
const PAUSED = 57786
View Source
const PER = 57787
View Source
const PERMISSIVE = 57788
View Source
const PHYSICAL = 57789
View Source
const PLACEHOLDER = 57352
View Source
const PLACEMENT = 57790
View Source
const PLACING = 57791
View Source
const PLAN = 57792
View Source
const PLANS = 57793
View Source
const POINT = 57794
View Source
const POINTM = 57795
View Source
const POINTZ = 57796
View Source
const POINTZM = 57797
View Source
const POLICIES = 57798
View Source
const POLICY = 57799
View Source
const POLYGON = 57800
View Source
const POLYGONM = 57801
View Source
const POLYGONZ = 57802
View Source
const POLYGONZM = 57803
View Source
const POSITION = 57804
View Source
const POSTFIXOP = 58062
View Source
const PRECEDING = 57805
View Source
const PRECISION = 57806
View Source
const PREPARE = 57807
View Source
const PREPARED = 57808
View Source
const PRESERVE = 57809
View Source
const PRIMARY = 57810
View Source
const PRIOR = 57811
View Source
const PRIORITY = 57812
View Source
const PRIVILEGES = 57813
View Source
const PROCEDURAL = 57814
View Source
const PROCEDURE = 57815
View Source
const PROCEDURES = 57816
View Source
const PUBLIC = 57817
View Source
const PUBLICATION = 57818
View Source
const QUERIES = 57819
View Source
const QUERY = 57820
View Source
const QUOTE = 57821
View Source
const RANGE = 57822
View Source
const RANGES = 57823
View Source
const READ = 57824
View Source
const REAL = 57825
View Source
const REASON = 57826
View Source
const REASSIGN = 57827
View Source
const RECURRING = 57829
View Source
const RECURSIVE = 57828
View Source
const REDACT = 57830
View Source
const REF = 57831
View Source
const REFERENCES = 57832
View Source
const REFERENCING = 57833
View Source
const REFRESH = 57834
View Source
const REGCLASS = 57835
View Source
const REGIMATCH = 57360
View Source
const REGION = 57836
View Source
const REGIONAL = 57837
View Source
const REGIONS = 57838
View Source
const REGNAMESPACE = 57839
View Source
const REGPROC = 57840
View Source
const REGPROCEDURE = 57841
View Source
const REGROLE = 57842
View Source
const REGTYPE = 57843
View Source
const REINDEX = 57844
View Source
const RELATIVE = 57845
View Source
const RELEASE = 57854
View Source
const RELOCATE = 57846
View Source
const REMOVE_PATH = 57847
View Source
const REMOVE_REGIONS = 57848
View Source
const RENAME = 57849
View Source
const REPEATABLE = 57850
View Source
const REPLACE = 57851
View Source
const REPLICATED = 57852
View Source
const REPLICATION = 57853
View Source
const RESET = 57855
View Source
const RESET_ALL = 58054
View Source
const RESTART = 57856
View Source
const RESTORE = 57857
View Source
const RESTRICT = 57858
View Source
const RESTRICTED = 57859
View Source
const RESTRICTIVE = 57860
View Source
const RESUME = 57861
View Source
const RETENTION = 57862
View Source
const RETRY = 57866
View Source
const RETURN = 57864
View Source
const RETURNING = 57863
View Source
const RETURNS = 57865
View Source
const REVISION_HISTORY = 57867
View Source
const REVOKE = 57868
View Source
const RIGHT = 57869
View Source
const ROLE = 57870
View Source
const ROLES = 57871
View Source
const ROLE_ALL = 58055
View Source
const ROLLBACK = 57872
View Source
const ROLLUP = 57873
View Source
const ROUTINES = 57874
View Source
const ROW = 57875
View Source
const ROWS = 57876
View Source
const RSHIFT = 57877
View Source
const RULE = 57878
View Source
const RUNNING = 57879
View Source
const SAVEPOINT = 57880
View Source
const SCANS = 57881
View Source
const SCATTER = 57882
View Source
const SCHEDULE = 57883
View Source
const SCHEDULES = 57884
View Source
const SCHEMA = 57886
View Source
const SCHEMAS = 57888
View Source
const SCHEMA_ONLY = 57887
View Source
const SCONST = 57347
View Source
const SCROLL = 57885
View Source
const SCRUB = 57889
View Source
const SEARCH = 57890
View Source
const SECOND = 57891
View Source
const SECONDARY = 57892
View Source
const SECURITY = 57893
View Source
const SELECT = 57894
View Source
const SEQUENCE = 57895
View Source
const SEQUENCES = 57896
View Source
const SERIALIZABLE = 57897
View Source
const SERVER = 57898
View Source
const SERVICE = 57899
View Source
const SESSION = 57900
View Source
const SESSIONS = 57901
View Source
const SESSION_USER = 57902
View Source
const SET = 57903
View Source
const SETOF = 57904
View Source
const SETS = 57905
View Source
const SETTING = 57906
View Source
const SETTINGS = 57907
View Source
const SET_TRACING = 58060
View Source
const SHARE = 57908
View Source
const SHARED = 57909
View Source
const SHOW = 57910
View Source
const SIMILAR = 57911
View Source
const SIMPLE = 57912
View Source
const SIZE = 57913
View Source
const SKIP = 57914
View Source
const SKIP_LOCALITIES_CHECK = 57915
View Source
const SKIP_MISSING_FOREIGN_KEYS = 57916
View Source
const SKIP_MISSING_SEQUENCES = 57917
View Source
const SKIP_MISSING_SEQUENCE_OWNERS = 57918
View Source
const SKIP_MISSING_UDFS = 57920
View Source
const SKIP_MISSING_VIEWS = 57919
View Source
const SMALLINT = 57921
View Source
const SMALLSERIAL = 57922
View Source
const SNAPSHOT = 57923
View Source
const SOME = 57924
View Source
const SOURCE = 57925
View Source
const SPLIT = 57926
View Source
const SQL = 57927
View Source
const SQLLOGIN = 57928
View Source
const SQRT = 57955
View Source
const STABLE = 57929
View Source
const START = 57930
View Source
const STATE = 57931
View Source
const STATEMENT = 57932
View Source
const STATEMENTS = 57957
View Source
const STATISTICS = 57933
View Source
const STATUS = 57934
View Source
const STDIN = 57935
View Source
const STDOUT = 57936
View Source
const STOP = 57937
View Source
const STORAGE = 57942
View Source
const STORE = 57943
View Source
const STORED = 57944
View Source
const STORING = 57945
View Source
const STRAIGHT = 57938
View Source
const STREAM = 57939
View Source
const STRICT = 57940
View Source
const STRING = 57941
View Source
const SUBJECT = 57946
View Source
const SUBSCRIPTION = 57956
View Source
const SUBSTRING = 57947
View Source
const SUPER = 57948
View Source
const SUPPORT = 57949
View Source
const SURVIVAL = 57951
View Source
const SURVIVE = 57950
View Source
const SYMMETRIC = 57952
View Source
const SYNTAX = 57953
View Source
const SYSTEM = 57954
View Source
const TABLE = 57958
View Source
const TABLES = 57959
View Source
const TABLESPACE = 57960
View Source
const TEMP = 57961
View Source
const TEMPLATE = 57962
View Source
const TEMPORARY = 57963
View Source
const TENANT = 57964
View Source
const TENANTS = 57966
View Source
const TENANT_ALL = 58058
View Source
const TENANT_NAME = 57965
View Source
const TESTING_RELOCATE = 57967
View Source
const TEXT = 57968
View Source
const THEN = 57969
View Source
const THROTTLING = 57976
View Source
const TIES = 57970
View Source
const TIME = 57971
View Source
const TIMESTAMP = 57973
View Source
const TIMESTAMPTZ = 57974
View Source
const TIMETZ = 57972
View Source
const TO = 57975
View Source
const TRACE = 57978
View Source
const TRACING = 57992
View Source
const TRAILING = 57977
View Source
const TRANSACTION = 57979
View Source
const TRANSACTIONS = 57980
View Source
const TRANSFER = 57981
View Source
const TRANSFORM = 57982
View Source
const TREAT = 57983
View Source
const TRIGGER = 57984
View Source
const TRIGGERS = 57985
View Source
const TRIM = 57986
View Source
const TRUE = 57987
View Source
const TRUNCATE = 57988
View Source
const TRUSTED = 57989
View Source
const TYPE = 57990
View Source
const TYPEANNOTATE = 57354
View Source
const TYPECAST = 57353
View Source
const TYPES = 57991
View Source
const UMINUS = 58064
View Source
const UNBOUNDED = 57993
View Source
const UNCOMMITTED = 57994
View Source
const UNIDIRECTIONAL = 57995
View Source
const UNION = 57996
View Source
const UNIQUE = 57997
View Source
const UNKNOWN = 57998
View Source
const UNLISTEN = 57999
View Source
const UNLOGGED = 58000
View Source
const UNSAFE_RESTORE_INCOMPATIBLE_VERSION = 58001
View Source
const UNSET = 58006
View Source
const UNSPLIT = 58002
View Source
const UNTIL = 58007
View Source
const UPDATE = 58003
View Source
const UPDATES_CLUSTER_MONITORING_METRICS = 58004
View Source
const UPSERT = 58005
View Source
const USE = 58008
View Source
const USER = 58009
View Source
const USERS = 58010
View Source
const USER_ALL = 58056
View Source
const USING = 58011
View Source
const UUID = 58012
View Source
const VALID = 58013
View Source
const VALIDATE = 58014
View Source
const VALUE = 58015
View Source
const VALUES = 58016
View Source
const VARBIT = 58017
View Source
const VARCHAR = 58018
View Source
const VARIABLES = 58023
View Source
const VARIADIC = 58019
View Source
const VARYING = 58024
View Source
const VECTOR = 58020
View Source
const VERIFY_BACKUP_TABLE_DATA = 58021
View Source
const VIEW = 58022
View Source
const VIEWACTIVITY = 58025
View Source
const VIEWACTIVITYREDACTED = 58026
View Source
const VIEWCLUSTERMETADATA = 58028
View Source
const VIEWCLUSTERSETTING = 58029
View Source
const VIEWDEBUG = 58027
View Source
const VIRTUAL = 58030
View Source
const VIRTUAL_CLUSTER = 58037
View Source
const VIRTUAL_CLUSTER_NAME = 58036
View Source
const VISIBILITY = 58033
View Source
const VISIBLE = 58031
View Source
const VOLATILE = 58034
View Source
const VOTERS = 58035
View Source
const WHEN = 58038
View Source
const WHERE = 58039
View Source
const WINDOW = 58040
View Source
const WITH = 58041
View Source
const WITHIN = 58042
View Source
const WITHOUT = 58043
View Source
const WITH_LA = 58050
View Source
const WORK = 58044
View Source
const WRITE = 58045
View Source
const YEAR = 58046
View Source
const ZONE = 58047

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", cases.Title(language.English, cases.NoLower).String(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", docs.URLBase, -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.

View Source
var ParseDoBlockFn func(tree.DoBlockOptions) (tree.DoBlockBody, error)

ParseDoBlockFn allows the SQL parser to parse a PL/pgSQL DO block body.

Functions

func GetTypeFromCastOrCollate

func GetTypeFromCastOrCollate(expr tree.Expr) (tree.ResolvableTypeReference, error)

GetTypeFromCastOrCollate returns the type of the given tree.Expr. The method assumes that the expression is either tree.CastExpr or tree.CollateExpr (which wraps the tree.CastExpr).

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 (or handling the resulting error). 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 Parse

func Parse(sql string) (statements.Statements, error)

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

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 ParseFunctionName added in v0.25.2

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

ParseFunctionName parses a function name. The function 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 function name (the caller is responsible for guaranteeing that only valid function names are provided as input).

func ParseOne

func ParseOne(sql string) (statements.Statement[tree.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, we expect that all user-generated SQL has been run through the ParseWithInt() function.

func ParseOneRetainComments added in v0.25.2

func ParseOneRetainComments(sql string) (statements.Statement[tree.Statement], error)

ParseOneRetainComments is similar to ParseOne, but it retains scanned comments in the returned statement's Comment field.

func ParseOneWithInt

func ParseOneWithInt(
	sql string, nakedIntType *types.T,
) (statements.Statement[tree.Statement], error)

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

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 ParseTablePattern

func ParseTablePattern(sql string) (tree.TablePattern, error)

ParseTablePattern parses a table pattern. 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). The last part may be '*' to denote a wildcard.

func ParseWithInt

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

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

func PopulateErrorDetails

func PopulateErrorDetails(
	tokID int32, lastTokStr string, lastTokPos int32, lastErr error, lIn string,
) error

PopulateErrorDetails properly wraps the "last error" field in the lexer.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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