parser

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: PostgreSQL Imports: 6 Imported by: 0

Documentation

Overview

Package parser implements a PostgreSQL-compatible SQL lexer and parser. This lexer is a direct translation of PostgreSQL's scan.l.

Package parser provides the public API for parsing PostgreSQL SQL.

Index

Constants

View Source
const (
	BackslashQuoteOff = iota
	BackslashQuoteOn
	BackslashQuoteSafeEncoding
)

BackslashQuote values

View Source
const (
	ONCONFLICT_NONE    = 0
	ONCONFLICT_NOTHING = 1
	ONCONFLICT_UPDATE  = 2
)

OnConflict action constants

View Source
const (
	VIEW_CHECK_OPTION_NONE     = 0
	VIEW_CHECK_OPTION_LOCAL    = 1
	VIEW_CHECK_OPTION_CASCADED = 2
)

ViewCheckOption constants

View Source
const (
	SET_QUANTIFIER_DEFAULT  = int64(0)
	SET_QUANTIFIER_ALL      = int64(1)
	SET_QUANTIFIER_DISTINCT = int64(2)
)

SetQuantifier constants matching PostgreSQL's SetQuantifier enum.

View Source
const ABORT_P = 57366
View Source
const ABSENT = 57367
View Source
const ABSOLUTE_P = 57368
View Source
const ACCESS = 57369
View Source
const ACTION = 57370
View Source
const ADD_P = 57371
View Source
const ADMIN = 57372
View Source
const AFTER = 57373
View Source
const AGGREGATE = 57374
View Source
const ALL = 57375
View Source
const ALSO = 57376
View Source
const ALTER = 57377
View Source
const ALWAYS = 57378
View Source
const ANALYSE = 57379
View Source
const ANALYZE = 57380
View Source
const AND = 57381
View Source
const ANY = 57382
View Source
const ARRAY = 57383
View Source
const AS = 57384
View Source
const ASC = 57385
View Source
const ASENSITIVE = 57386
View Source
const ASSERTION = 57387
View Source
const ASSIGNMENT = 57388
View Source
const ASYMMETRIC = 57389
View Source
const AT = 57391
View Source
const ATOMIC = 57390
View Source
const ATTACH = 57392
View Source
const ATTRIBUTE = 57393
View Source
const AUTHORIZATION = 57394
View Source
const BACKWARD = 57395
View Source
const BCONST = 57349
View Source
const BEFORE = 57396
View Source
const BEGIN_P = 57397
View Source
const BETWEEN = 57398
View Source
const BIGINT = 57399
View Source
const BINARY = 57400
View Source
const BIT = 57401
View Source
const BOOLEAN_P = 57402
View Source
const BOTH = 57403
View Source
const BREADTH = 57404
View Source
const BY = 57405
View Source
const CACHE = 57406
View Source
const CALL = 57407
View Source
const CALLED = 57408
View Source
const CASCADE = 57409
View Source
const CASCADED = 57410
View Source
const CASE = 57411
View Source
const CAST = 57412
View Source
const CATALOG_P = 57413
View Source
const CHAIN = 57414
View Source
const CHARACTER = 57416
View Source
const CHARACTERISTICS = 57417
View Source
const CHAR_P = 57415
View Source
const CHECK = 57418
View Source
const CHECKPOINT = 57419
View Source
const CLASS = 57420
View Source
const CLOSE = 57421
View Source
const CLUSTER = 57422
View Source
const COALESCE = 57423
View Source
const COLLATE = 57424
View Source
const COLLATION = 57425
View Source
const COLON_EQUALS = 57356
View Source
const COLUMN = 57426
View Source
const COLUMNS = 57427
View Source
const COMMENT = 57428
View Source
const COMMENTS = 57429
View Source
const COMMIT = 57430
View Source
const COMMITTED = 57431
View Source
const COMPRESSION = 57432
View Source
const CONCURRENTLY = 57433
View Source
const CONDITIONAL = 57434
View Source
const CONFIGURATION = 57435
View Source
const CONFLICT = 57436
View Source
const CONNECTION = 57437
View Source
const CONSTRAINT = 57438
View Source
const CONSTRAINTS = 57439
View Source
const CONTENT_P = 57440
View Source
const CONTINUE_P = 57441
View Source
const CONVERSION_P = 57442
View Source
const COPY = 57443
View Source
const COST = 57444
View Source
const CREATE = 57445
View Source
const CROSS = 57446
View Source
const CSV = 57447
View Source
const CUBE = 57448
View Source
const CURRENT_CATALOG = 57450
View Source
const CURRENT_DATE = 57451
View Source
const CURRENT_P = 57449
View Source
const CURRENT_ROLE = 57452
View Source
const CURRENT_SCHEMA = 57453
View Source
const CURRENT_TIME = 57454
View Source
const CURRENT_TIMESTAMP = 57455
View Source
const CURRENT_USER = 57456
View Source
const CURSOR = 57457
View Source
const CYCLE = 57458
View Source
const DATABASE = 57460
View Source
const DATA_P = 57459
View Source
const DAY_P = 57461
View Source
const DEALLOCATE = 57462
View Source
const DEC = 57463
View Source
const DECIMAL_P = 57464
View Source
const DECLARE = 57465
View Source
const DEFAULT = 57466
View Source
const DEFAULTS = 57467
View Source
const DEFERRABLE = 57468
View Source
const DEFERRED = 57469
View Source
const DEFINER = 57470
View Source
const DELETE_P = 57471
View Source
const DELIMITER = 57472
View Source
const DELIMITERS = 57473
View Source
const DEPENDS = 57474
View Source
const DEPTH = 57475
View Source
const DESC = 57476
View Source
const DETACH = 57477
View Source
const DICTIONARY = 57478
View Source
const DISABLE_P = 57479
View Source
const DISCARD = 57480
View Source
const DISTINCT = 57481
View Source
const DO = 57482
View Source
const DOCUMENT_P = 57483
View Source
const DOMAIN_P = 57484
View Source
const DOT_DOT = 57355
View Source
const DOUBLE_P = 57485
View Source
const DROP = 57486
View Source
const EACH = 57487
View Source
const ELSE = 57488
View Source
const EMPTY_P = 57489
View Source
const ENABLE_P = 57490
View Source
const ENCODING = 57491
View Source
const ENCRYPTED = 57492
View Source
const END_P = 57493
View Source
const ENUM_P = 57494
View Source
const EQUALS_GREATER = 57357
View Source
const ERROR_P = 57495
View Source
const ESCAPE = 57496
View Source
const EVENT = 57497
View Source
const EXCEPT = 57498
View Source
const EXCLUDE = 57499
View Source
const EXCLUDING = 57500
View Source
const EXCLUSIVE = 57501
View Source
const EXECUTE = 57502
View Source
const EXISTS = 57503
View Source
const EXPLAIN = 57504
View Source
const EXPRESSION = 57505
View Source
const EXTENSION = 57506
View Source
const EXTERNAL = 57507
View Source
const EXTRACT = 57508
View Source
const FALSE_P = 57509
View Source
const FAMILY = 57510
View Source
const FCONST = 57347
View Source
const FETCH = 57511
View Source
const FILTER = 57512
View Source
const FINALIZE = 57513
View Source
const FIRST_P = 57514
View Source
const FLOAT_P = 57515
View Source
const FOLLOWING = 57516
View Source
const FOR = 57517
View Source
const FORCE = 57518
View Source
const FOREIGN = 57519
View Source
const FORMAT = 57520
View Source
const FORMAT_LA = 57364
View Source
const FORWARD = 57521
View Source
const FREEZE = 57522
View Source
const FROM = 57523
View Source
const FULL = 57524
View Source
const FUNCTION = 57525
View Source
const FUNCTIONS = 57526
View Source
const GENERATED = 57527
View Source
const GLOBAL = 57528
View Source
const GRANT = 57529
View Source
const GRANTED = 57530
View Source
const GREATER_EQUALS = 57359
View Source
const GREATEST = 57531
View Source
const GROUPING = 57533
View Source
const GROUPS = 57534
View Source
const GROUP_P = 57532
View Source
const HANDLER = 57535
View Source
const HAVING = 57536
View Source
const HEADER_P = 57537
View Source
const HOLD = 57538
View Source
const HOUR_P = 57539
View Source
const ICONST = 57352
View Source
const IDENT = 57346
View Source
const IDENTITY_P = 57540
View Source
const IF_P = 57541
View Source
const ILIKE = 57542
View Source
const IMMEDIATE = 57543
View Source
const IMMUTABLE = 57544
View Source
const IMPLICIT_P = 57545
View Source
const IMPORT_P = 57546
View Source
const INCLUDE = 57548
View Source
const INCLUDING = 57549
View Source
const INCREMENT = 57550
View Source
const INDENT = 57551
View Source
const INDEX = 57552
View Source
const INDEXES = 57553
View Source
const INHERIT = 57554
View Source
const INHERITS = 57555
View Source
const INITIALLY = 57556
View Source
const INLINE_P = 57557
View Source
const INNER_P = 57558
View Source
const INOUT = 57559
View Source
const INPUT_P = 57560
View Source
const INSENSITIVE = 57561
View Source
const INSERT = 57562
View Source
const INSTEAD = 57563
View Source
const INTEGER = 57565
View Source
const INTERSECT = 57566
View Source
const INTERVAL = 57567
View Source
const INTO = 57568
View Source
const INT_P = 57564
View Source
const INVOKER = 57569
View Source
const IN_P = 57547
View Source
const IS = 57570
View Source
const ISNULL = 57571
View Source
const ISOLATION = 57572
View Source
const JOIN = 57573
View Source
const JSON = 57574
View Source
const JSON_ARRAY = 57575
View Source
const JSON_ARRAYAGG = 57576
View Source
const JSON_EXISTS = 57577
View Source
const JSON_OBJECT = 57578
View Source
const JSON_OBJECTAGG = 57579
View Source
const JSON_QUERY = 57580
View Source
const JSON_SCALAR = 57581
View Source
const JSON_SERIALIZE = 57582
View Source
const JSON_TABLE = 57583
View Source
const JSON_VALUE = 57584
View Source
const KEEP = 57585
View Source
const KEY = 57586
View Source
const KEYS = 57587
View Source
const LABEL = 57588
View Source
const LANGUAGE = 57589
View Source
const LARGE_P = 57590
View Source
const LAST_P = 57591
View Source
const LATERAL_P = 57592
View Source
const LEADING = 57593
View Source
const LEAKPROOF = 57594
View Source
const LEAST = 57595
View Source
const LEFT = 57596
View Source
const LESS_EQUALS = 57358
View Source
const LEVEL = 57597
View Source
const LIKE = 57598
View Source
const LIMIT = 57599
View Source
const LISTEN = 57600
View Source
const LOAD = 57601
View Source
const LOCAL = 57602
View Source
const LOCALTIME = 57603
View Source
const LOCALTIMESTAMP = 57604
View Source
const LOCATION = 57605
View Source
const LOCKED = 57607
View Source
const LOCK_P = 57606
View Source
const LOGGED = 57608
View Source
const MAPPING = 57609
View Source
const MATCH = 57610
View Source
const MATCHED = 57611
View Source
const MATERIALIZED = 57612
View Source
const MAXVALUE = 57613
View Source
const MERGE = 57614
View Source
const MERGE_ACTION = 57615
View Source
const METHOD = 57616
View Source
const MINUTE_P = 57617
View Source
const MINVALUE = 57618
View Source
const MODE = 57619
View Source
const MONTH_P = 57620
View Source
const MOVE = 57621
View Source
const NAMES = 57623
View Source
const NAME_P = 57622
View Source
const NATIONAL = 57624
View Source
const NATURAL = 57625
View Source
const NCHAR = 57626
View Source
const NESTED = 57627
View Source
const NEW = 57628
View Source
const NEXT = 57629
View Source
const NFC = 57630
View Source
const NFD = 57631
View Source
const NFKC = 57632
View Source
const NFKD = 57633
View Source
const NO = 57634
View Source
const NONE = 57635
View Source
const NORMALIZE = 57636
View Source
const NORMALIZED = 57637
View Source
const NOT = 57638
View Source
const NOTHING = 57639
View Source
const NOTIFY = 57640
View Source
const NOTNULL = 57641
View Source
const NOT_EQUALS = 57360
View Source
const NOT_LA = 57361
View Source
const NOWAIT = 57642
View Source
const NULLIF = 57644
View Source
const NULLS_LA = 57363
View Source
const NULLS_P = 57645
View Source
const NULL_P = 57643
View Source
const NUMERIC = 57646
View Source
const OBJECT_P = 57647
View Source
const OF = 57648
View Source
const OFF = 57649
View Source
const OFFSET = 57650
View Source
const OIDS = 57651
View Source
const OLD = 57652
View Source
const OMIT = 57653
View Source
const ON = 57654
View Source
const ONLY = 57655
View Source
const OPERATOR = 57656
View Source
const OPTION = 57657
View Source
const OPTIONS = 57658
View Source
const OR = 57659
View Source
const ORDER = 57660
View Source
const ORDINALITY = 57661
View Source
const OTHERS = 57662
View Source
const OUTER_P = 57664
View Source
const OUT_P = 57663
View Source
const OVER = 57665
View Source
const OVERLAPS = 57666
View Source
const OVERLAY = 57667
View Source
const OVERRIDING = 57668
View Source
const OWNED = 57669
View Source
const OWNER = 57670
View Source
const Op = 57351
View Source
const PARALLEL = 57671
View Source
const PARAM = 57353
View Source
const PARAMETER = 57672
View Source
const PARSER = 57673
View Source
const PARTIAL = 57674
View Source
const PARTITION = 57675
View Source
const PASSING = 57676
View Source
const PASSWORD = 57677
View Source
const PATH = 57678
View Source
const PLACING = 57679
View Source
const PLAN = 57680
View Source
const PLANS = 57681
View Source
const POLICY = 57682
View Source
const POSITION = 57683
View Source
const PRECEDING = 57684
View Source
const PRECISION = 57685
View Source
const PREPARE = 57687
View Source
const PREPARED = 57688
View Source
const PRESERVE = 57686
View Source
const PRIMARY = 57689
View Source
const PRIOR = 57690
View Source
const PRIVILEGES = 57691
View Source
const PROCEDURAL = 57692
View Source
const PROCEDURE = 57693
View Source
const PROCEDURES = 57694
View Source
const PROGRAM = 57695
View Source
const PUBLICATION = 57696
View Source
const QUOTE = 57697
View Source
const QUOTES = 57698
View Source
const RANGE = 57699
View Source
const READ = 57700
View Source
const REAL = 57701
View Source
const REASSIGN = 57702
View Source
const RECHECK = 57703
View Source
const RECURSIVE = 57704
View Source
const REFERENCES = 57706
View Source
const REFERENCING = 57707
View Source
const REFRESH = 57708
View Source
const REF_P = 57705
View Source
const REINDEX = 57709
View Source
const RELATIVE_P = 57710
View Source
const RELEASE = 57711
View Source
const RENAME = 57712
View Source
const REPEATABLE = 57713
View Source
const REPLACE = 57714
View Source
const REPLICA = 57715
View Source
const RESET = 57716
View Source
const RESTART = 57717
View Source
const RESTRICT = 57718
View Source
const RETURN = 57719
View Source
const RETURNING = 57720
View Source
const RETURNS = 57721
View Source
const REVOKE = 57722
View Source
const RIGHT = 57723
View Source
const ROLE = 57724
View Source
const ROLLBACK = 57725
View Source
const ROLLUP = 57726
View Source
const ROUTINE = 57727
View Source
const ROUTINES = 57728
View Source
const ROW = 57729
View Source
const ROWS = 57730
View Source
const RULE = 57731
View Source
const SAVEPOINT = 57732
View Source
const SCALAR = 57733
View Source
const SCHEMA = 57734
View Source
const SCHEMAS = 57735
View Source
const SCONST = 57348
View Source
const SCROLL = 57736
View Source
const SEARCH = 57737
View Source
const SECOND_P = 57738
View Source
const SECURITY = 57739
View Source
const SELECT = 57740
View Source
const SEQUENCE = 57741
View Source
const SEQUENCES = 57742
View Source
const SERIALIZABLE = 57743
View Source
const SERVER = 57744
View Source
const SESSION = 57745
View Source
const SESSION_USER = 57746
View Source
const SET = 57747
View Source
const SETOF = 57749
View Source
const SETS = 57748
View Source
const SHARE = 57750
View Source
const SHOW = 57751
View Source
const SIMILAR = 57752
View Source
const SIMPLE = 57753
View Source
const SKIP = 57754
View Source
const SMALLINT = 57755
View Source
const SNAPSHOT = 57756
View Source
const SOME = 57757
View Source
const SOURCE = 57758
View Source
const SQL_P = 57759
View Source
const STABLE = 57760
View Source
const STANDALONE_P = 57761
View Source
const START = 57762
View Source
const STATEMENT = 57763
View Source
const STATISTICS = 57764
View Source
const STDIN = 57765
View Source
const STDOUT = 57766
View Source
const STORAGE = 57767
View Source
const STORED = 57768
View Source
const STRICT_P = 57769
View Source
const STRING_P = 57770
View Source
const STRIP_P = 57771
View Source
const SUBSCRIPTION = 57772
View Source
const SUBSTRING = 57773
View Source
const SUPPORT = 57774
View Source
const SYMMETRIC = 57775
View Source
const SYSID = 57776
View Source
const SYSTEM_P = 57777
View Source
const SYSTEM_USER = 57778
View Source
const TABLE = 57779
View Source
const TABLES = 57780
View Source
const TABLESAMPLE = 57781
View Source
const TABLESPACE = 57782
View Source
const TARGET = 57783
View Source
const TEMP = 57784
View Source
const TEMPLATE = 57785
View Source
const TEMPORARY = 57786
View Source
const TEXT_P = 57787
View Source
const THEN = 57788
View Source
const TIES = 57789
View Source
const TIME = 57790
View Source
const TIMESTAMP = 57791
View Source
const TO = 57792
View Source
const TRAILING = 57793
View Source
const TRANSACTION = 57794
View Source
const TRANSFORM = 57795
View Source
const TREAT = 57796
View Source
const TRIGGER = 57797
View Source
const TRIM = 57798
View Source
const TRUE_P = 57799
View Source
const TRUNCATE = 57800
View Source
const TRUSTED = 57801
View Source
const TYPECAST = 57354
View Source
const TYPES_P = 57803
View Source
const TYPE_P = 57802
View Source
const UESCAPE = 57804
View Source
const UMINUS = 57857
View Source
const UNBOUNDED = 57805
View Source
const UNCOMMITTED = 57807
View Source
const UNCONDITIONAL = 57806
View Source
const UNENCRYPTED = 57808
View Source
const UNION = 57809
View Source
const UNIQUE = 57810
View Source
const UNKNOWN = 57811
View Source
const UNLISTEN = 57812
View Source
const UNLOGGED = 57813
View Source
const UNTIL = 57814
View Source
const UPDATE = 57815
View Source
const USER = 57816
View Source
const USING = 57817
View Source
const VACUUM = 57818
View Source
const VALID = 57819
View Source
const VALIDATE = 57820
View Source
const VALIDATOR = 57821
View Source
const VALUES = 57823
View Source
const VALUE_P = 57822
View Source
const VARCHAR = 57824
View Source
const VARIADIC = 57825
View Source
const VARYING = 57826
View Source
const VERBOSE = 57827
View Source
const VERSION_P = 57828
View Source
const VIEW = 57829
View Source
const VIEWS = 57830
View Source
const VOLATILE = 57831
View Source
const WHEN = 57832
View Source
const WHERE = 57833
View Source
const WHITESPACE_P = 57834
View Source
const WINDOW = 57835
View Source
const WITH = 57836
View Source
const WITHIN = 57837
View Source
const WITHOUT = 57838
View Source
const WITHOUT_LA = 57365
View Source
const WITH_LA = 57362
View Source
const WORK = 57839
View Source
const WRAPPER = 57840
View Source
const WRITE = 57841
View Source
const XCONST = 57350
View Source
const XMLATTRIBUTES = 57843
View Source
const XMLCONCAT = 57844
View Source
const XMLELEMENT = 57845
View Source
const XMLEXISTS = 57846
View Source
const XMLFOREST = 57847
View Source
const XMLNAMESPACES = 57848
View Source
const XMLPARSE = 57849
View Source
const XMLPI = 57850
View Source
const XMLROOT = 57851
View Source
const XMLSERIALIZE = 57852
View Source
const XMLTABLE = 57853
View Source
const XML_P = 57842
View Source
const YEAR_P = 57854
View Source
const YES_P = 57855
View Source
const ZONE = 57856

Variables

View Source
var Keywords = []Keyword{}/* 491 elements not displayed */

Keywords is the list of all PostgreSQL keywords. The list is sorted by keyword name for binary search.

Functions

func Parse

func Parse(input string) (*nodes.List, error)

Parse parses the given SQL input and returns a list of statements.

Types

type GroupClause

type GroupClause struct {
	Distinct bool
	List     *nodes.List
}

GroupClause is an internal helper struct for passing GROUP BY clause distinct flag and list through grammar rules (matches PostgreSQL's GroupClause).

type KeyAction

type KeyAction struct {
	Action byte
	Cols   *nodes.List
}

KeyAction is an internal helper struct for passing FK action and column list through grammar rules (matches PostgreSQL's KeyAction).

type KeyActions

type KeyActions struct {
	UpdateAction *KeyAction
	DeleteAction *KeyAction
}

KeyActions is an internal helper struct for passing FK update/delete actions through grammar rules (matches PostgreSQL's KeyActions).

type Keyword

type Keyword struct {
	Name     string
	Token    int
	Category KeywordCategory
}

Keyword represents a PostgreSQL keyword.

func LookupKeyword

func LookupKeyword(name string) *Keyword

LookupKeyword looks up a keyword by name (case-insensitive). Returns nil if not found.

type KeywordCategory

type KeywordCategory int

KeywordCategory represents the PostgreSQL keyword category.

const (
	UnreservedKeyword KeywordCategory = iota
	ColNameKeyword
	TypeFuncNameKeyword
	ReservedKeyword
)

type Lexer

type Lexer struct {

	// Configuration
	StandardConformingStrings bool // If true, backslash is not escape in standard strings
	BackslashQuote            int  // 0=off, 1=on, 2=safe_encoding
	EscapeStringWarning       bool

	// Error handling
	Err error
	// contains filtered or unexported fields
}

Lexer implements a PostgreSQL-compatible SQL lexer.

func NewLexer

func NewLexer(input string) *Lexer

NewLexer creates a new lexer for the given input.

func (*Lexer) NextToken

func (l *Lexer) NextToken() Token

NextToken returns the next token from the input.

type LexerState

type LexerState int

LexerState represents the current state of the lexer (for string/comment handling).

type ParseError

type ParseError struct {
	Message  string
	Position int
}

ParseError represents a parse error with position information.

func (*ParseError) Error

func (e *ParseError) Error() string

type ParseResult

type ParseResult struct {
	Stmts []*nodes.RawStmt
	Err   error
}

ParseResult contains the result of parsing.

type SelectLimit

type SelectLimit struct {
	LimitOffset nodes.Node
	LimitCount  nodes.Node
	LimitOption nodes.LimitOption
}

SelectLimit is an internal helper struct for passing LIMIT/OFFSET through grammar rules. It is not a Node type - just used during parsing.

type Token

type Token struct {
	Type int    // Token type (IDENT, ICONST, keyword token, etc.)
	Str  string // String value for identifiers, operators, string literals
	Ival int64  // Integer value for ICONST
	Loc  int    // Byte offset in the source text
}

Token represents a lexical token.

Directories

Path Synopsis
Package pgregress provides tools for running PostgreSQL regression test SQL files against the pgparser parser to verify parse compatibility.
Package pgregress provides tools for running PostgreSQL regression test SQL files against the pgparser parser to verify parse compatibility.

Jump to

Keyboard shortcuts

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