Documentation ¶
Index ¶
- Constants
- Variables
- func DocsURL(pageName string) string
- func EndsInSemicolon(sql string) bool
- func LastLexicalToken(sql string) (lastTok int, ok bool)
- func ParseExpr(sql string) (tree.Expr, error)
- func ParseExprs(sql []string) (tree.Exprs, error)
- func ParseQualifiedTableName(sql string) (*tree.TableName, error)
- func ParseTableName(sql string) (*tree.UnresolvedObjectName, error)
- func ParseType(sql string) (*types.T, error)
- func RunShowSyntax(ctx context.Context, stmt string, ...)
- func SplitFirstStatement(sql string) (pos int, ok bool)
- type HelpMessage
- type HelpMessageBody
- type Parser
- type Statement
- type Statements
- type TokenString
Constants ¶
const ABORT = lex.ABORT
const ACTION = lex.ACTION
const ADD = lex.ADD
const ADMIN = lex.ADMIN
const AGGREGATE = lex.AGGREGATE
const ALL = lex.ALL
const ALTER = lex.ALTER
const ANALYSE = lex.ANALYSE
const ANALYZE = lex.ANALYZE
const AND = lex.AND
const AND_AND = lex.AND_AND
const ANNOTATE_TYPE = lex.ANNOTATE_TYPE
const ANY = lex.ANY
const ARRAY = lex.ARRAY
const AS = lex.AS
const ASC = lex.ASC
const ASYMMETRIC = lex.ASYMMETRIC
const AS_LA = lex.AS_LA
const AT = lex.AT
const AUTHORIZATION = lex.AUTHORIZATION
const AUTOMATIC = lex.AUTOMATIC
const BACKUP = lex.BACKUP
const BCONST = lex.BCONST
const BEGIN = lex.BEGIN
const BETWEEN = lex.BETWEEN
const BIGINT = lex.BIGINT
const BIGSERIAL = lex.BIGSERIAL
const BIT = lex.BIT
const BITCONST = lex.BITCONST
const BLOB = lex.BLOB
const BOOL = lex.BOOL
const BOOLEAN = lex.BOOLEAN
const BOTH = lex.BOTH
const BUCKET_COUNT = lex.BUCKET_COUNT
const BUNDLE = lex.BUNDLE
const BY = lex.BY
const BYTEA = lex.BYTEA
const BYTES = lex.BYTES
const CACHE = lex.CACHE
const CANCEL = lex.CANCEL
const CASCADE = lex.CASCADE
const CASE = lex.CASE
const CAST = lex.CAST
const CHANGEFEED = lex.CHANGEFEED
const CHAR = lex.CHAR
const CHARACTER = lex.CHARACTER
const CHARACTERISTICS = lex.CHARACTERISTICS
const CHECK = lex.CHECK
const CLUSTER = lex.CLUSTER
const COALESCE = lex.COALESCE
const COLLATE = lex.COLLATE
const COLLATION = lex.COLLATION
const COLUMN = lex.COLUMN
const COLUMNS = lex.COLUMNS
const COMMENT = lex.COMMENT
const COMMIT = lex.COMMIT
const COMMITTED = lex.COMMITTED
const COMPACT = lex.COMPACT
const COMPLETE = lex.COMPLETE
const CONCAT = lex.CONCAT
const CONCURRENTLY = lex.CONCURRENTLY
const CONFIGURATION = lex.CONFIGURATION
const CONFIGURATIONS = lex.CONFIGURATIONS
const CONFIGURE = lex.CONFIGURE
const CONFLICT = lex.CONFLICT
const CONSTRAINT = lex.CONSTRAINT
const CONSTRAINTS = lex.CONSTRAINTS
const CONTAINED_BY = lex.CONTAINED_BY
const CONTAINS = lex.CONTAINS
const CONVERSION = lex.CONVERSION
const COPY = lex.COPY
const COVERING = lex.COVERING
const CREATE = lex.CREATE
const CREATEROLE = lex.CREATEROLE
const CROSS = lex.CROSS
const CUBE = lex.CUBE
const CURRENT = lex.CURRENT
const CURRENT_CATALOG = lex.CURRENT_CATALOG
const CURRENT_DATE = lex.CURRENT_DATE
const CURRENT_ROLE = lex.CURRENT_ROLE
const CURRENT_SCHEMA = lex.CURRENT_SCHEMA
const CURRENT_TIME = lex.CURRENT_TIME
const CURRENT_TIMESTAMP = lex.CURRENT_TIMESTAMP
const CURRENT_USER = lex.CURRENT_USER
const CYCLE = lex.CYCLE
const DATA = lex.DATA
const DATABASE = lex.DATABASE
const DATABASES = lex.DATABASES
const DATE = lex.DATE
const DAY = lex.DAY
const DEALLOCATE = lex.DEALLOCATE
const DEC = lex.DEC
const DECIMAL = lex.DECIMAL
const DEFAULT = lex.DEFAULT
const DEFERRABLE = lex.DEFERRABLE
const DEFERRED = lex.DEFERRED
const DELETE = lex.DELETE
const DESC = lex.DESC
const DISCARD = lex.DISCARD
const DISTINCT = lex.DISTINCT
const DO = lex.DO
const DOMAIN = lex.DOMAIN
const DOT_DOT = lex.DOT_DOT
const DOUBLE = lex.DOUBLE
const DROP = lex.DROP
const ELSE = lex.ELSE
const ENCODING = lex.ENCODING
const END = lex.END
const ENUM = lex.ENUM
const ERROR = lex.ERROR
const ESCAPE = lex.ESCAPE
const EXCEPT = lex.EXCEPT
const EXCLUDE = lex.EXCLUDE
const EXECUTE = lex.EXECUTE
const EXISTS = lex.EXISTS
const EXPERIMENTAL = lex.EXPERIMENTAL
const EXPERIMENTAL_AUDIT = lex.EXPERIMENTAL_AUDIT
const EXPERIMENTAL_FINGERPRINTS = lex.EXPERIMENTAL_FINGERPRINTS
const EXPERIMENTAL_RELOCATE = lex.EXPERIMENTAL_RELOCATE
const EXPERIMENTAL_REPLICA = lex.EXPERIMENTAL_REPLICA
const EXPIRATION = lex.EXPIRATION
const EXPLAIN = lex.EXPLAIN
const EXPORT = lex.EXPORT
const EXTENSION = lex.EXTENSION
const EXTRACT = lex.EXTRACT
const EXTRACT_DURATION = lex.EXTRACT_DURATION
const FALSE = lex.FALSE
const FAMILY = lex.FAMILY
const FCONST = lex.FCONST
const FETCH = lex.FETCH
const FETCHTEXT = lex.FETCHTEXT
const FETCHTEXT_PATH = lex.FETCHTEXT_PATH
const FETCHVAL = lex.FETCHVAL
const FETCHVAL_PATH = lex.FETCHVAL_PATH
const FILES = lex.FILES
const FILTER = lex.FILTER
const FIRST = lex.FIRST
const FLOAT = lex.FLOAT
const FLOAT4 = lex.FLOAT4
const FLOAT8 = lex.FLOAT8
const FLOORDIV = lex.FLOORDIV
const FOLLOWING = lex.FOLLOWING
const FOR = lex.FOR
const FORCE_INDEX = lex.FORCE_INDEX
const FOREIGN = lex.FOREIGN
const FROM = lex.FROM
const FULL = lex.FULL
const FUNCTION = lex.FUNCTION
const GLOBAL = lex.GLOBAL
const GRANT = lex.GRANT
const GRANTS = lex.GRANTS
const GREATER_EQUALS = lex.GREATER_EQUALS
const GREATEST = lex.GREATEST
const GROUP = lex.GROUP
const GROUPING = lex.GROUPING
const GROUPS = lex.GROUPS
const HASH = lex.HASH
const HAVING = lex.HAVING
const HELPTOKEN = lex.HELPTOKEN
const HIGH = lex.HIGH
const HISTOGRAM = lex.HISTOGRAM
const HOUR = lex.HOUR
const ICONST = lex.ICONST
const IDENT = lex.IDENT
const IF = lex.IF
const IFERROR = lex.IFERROR
const IFNULL = lex.IFNULL
const IGNORE_FOREIGN_KEYS = lex.IGNORE_FOREIGN_KEYS
const ILIKE = lex.ILIKE
const IMMEDIATE = lex.IMMEDIATE
const IMPORT = lex.IMPORT
const IN = lex.IN
const INCLUDE = lex.INCLUDE
const INCREMENT = lex.INCREMENT
const INCREMENTAL = lex.INCREMENTAL
const INDEX = lex.INDEX
const INDEXES = lex.INDEXES
const INET = lex.INET
const INET_CONTAINED_BY_OR_EQUALS = lex.INET_CONTAINED_BY_OR_EQUALS
const INET_CONTAINS_OR_EQUALS = lex.INET_CONTAINS_OR_EQUALS
const INITIALLY = lex.INITIALLY
const INJECT = lex.INJECT
const INNER = lex.INNER
const INSERT = lex.INSERT
const INT = lex.INT
const INT2 = lex.INT2
const INT2VECTOR = lex.INT2VECTOR
const INT4 = lex.INT4
const INT64 = lex.INT64
const INT8 = lex.INT8
const INTEGER = lex.INTEGER
const INTERLEAVE = lex.INTERLEAVE
const INTERSECT = lex.INTERSECT
const INTERVAL = lex.INTERVAL
const INTO = lex.INTO
const INVERTED = lex.INVERTED
const IS = lex.IS
const ISERROR = lex.ISERROR
const ISNULL = lex.ISNULL
const ISOLATION = lex.ISOLATION
const JOB = lex.JOB
const JOBS = lex.JOBS
const JOIN = lex.JOIN
const JSON = lex.JSON
const JSONB = lex.JSONB
const JSON_ALL_EXISTS = lex.JSON_ALL_EXISTS
const JSON_SOME_EXISTS = lex.JSON_SOME_EXISTS
const KEY = lex.KEY
const KEYS = lex.KEYS
const KV = lex.KV
const LANGUAGE = lex.LANGUAGE
const LAST = lex.LAST
const LATERAL = lex.LATERAL
const LC_COLLATE = lex.LC_COLLATE
const LC_CTYPE = lex.LC_CTYPE
const LEADING = lex.LEADING
const LEASE = lex.LEASE
const LEAST = lex.LEAST
const LEFT = lex.LEFT
const LESS = lex.LESS
const LESS_EQUALS = lex.LESS_EQUALS
const LEVEL = lex.LEVEL
const LIKE = lex.LIKE
const LIMIT = lex.LIMIT
const LIST = lex.LIST
const LOCAL = lex.LOCAL
const LOCALTIME = lex.LOCALTIME
const LOCALTIMESTAMP = lex.LOCALTIMESTAMP
const LOCKED = lex.LOCKED
const LOGIN = lex.LOGIN
const LOOKUP = lex.LOOKUP
const LOW = lex.LOW
const LSHIFT = lex.LSHIFT
const MATCH = lex.MATCH
const MATERIALIZED = lex.MATERIALIZED
const MAXVALUE = lex.MAXVALUE
const MERGE = lex.MERGE
const MINUTE = lex.MINUTE
const MINVALUE = lex.MINVALUE
const MONTH = lex.MONTH
const MaxInt = int(MaxUint >> 1)
const MaxUint = ^uint(0)
const NAME = lex.NAME
const NAMES = lex.NAMES
const NAN = lex.NAN
const NATURAL = lex.NATURAL
const NEXT = lex.NEXT
const NO = lex.NO
const NOCREATEROLE = lex.NOCREATEROLE
const NOLOGIN = lex.NOLOGIN
const NONE = lex.NONE
const NORMAL = lex.NORMAL
const NOT = lex.NOT
const NOTHING = lex.NOTHING
const NOTNULL = lex.NOTNULL
const NOT_EQUALS = lex.NOT_EQUALS
const NOT_LA = lex.NOT_LA
const NOT_REGIMATCH = lex.NOT_REGIMATCH
const NOT_REGMATCH = lex.NOT_REGMATCH
const NOWAIT = lex.NOWAIT
const NO_INDEX_JOIN = lex.NO_INDEX_JOIN
const NULL = lex.NULL
const NULLIF = lex.NULLIF
const NULLS = lex.NULLS
const NUMERIC = lex.NUMERIC
const OF = lex.OF
const OFF = lex.OFF
const OFFSET = lex.OFFSET
const OID = lex.OID
const OIDS = lex.OIDS
const OIDVECTOR = lex.OIDVECTOR
const ON = lex.ON
const ONLY = lex.ONLY
const OPERATOR = lex.OPERATOR
const OPT = lex.OPT
const OPTION = lex.OPTION
const OPTIONS = lex.OPTIONS
const OR = lex.OR
const ORDER = lex.ORDER
const ORDINALITY = lex.ORDINALITY
const OTHERS = lex.OTHERS
const OUT = lex.OUT
const OUTER = lex.OUTER
const OVER = lex.OVER
const OVERLAPS = lex.OVERLAPS
const OVERLAY = lex.OVERLAY
const OWNED = lex.OWNED
const PARENT = lex.PARENT
const PARTIAL = lex.PARTIAL
const PARTITION = lex.PARTITION
const PARTITIONS = lex.PARTITIONS
const PASSWORD = lex.PASSWORD
const PAUSE = lex.PAUSE
const PHYSICAL = lex.PHYSICAL
const PLACEHOLDER = lex.PLACEHOLDER
const PLACING = lex.PLACING
const PLAN = lex.PLAN
const PLANS = lex.PLANS
const POSITION = lex.POSITION
const POSTFIXOP = lex.POSTFIXOP
const PRECEDING = lex.PRECEDING
const PRECISION = lex.PRECISION
const PREPARE = lex.PREPARE
const PRESERVE = lex.PRESERVE
const PRIMARY = lex.PRIMARY
const PRIORITY = lex.PRIORITY
const PROCEDURAL = lex.PROCEDURAL
const PUBLIC = lex.PUBLIC
const PUBLICATION = lex.PUBLICATION
const QUERIES = lex.QUERIES
const QUERY = lex.QUERY
const RANGE = lex.RANGE
const RANGES = lex.RANGES
const READ = lex.READ
const REAL = lex.REAL
const RECURSIVE = lex.RECURSIVE
const REF = lex.REF
const REFERENCES = lex.REFERENCES
const REGCLASS = lex.REGCLASS
const REGIMATCH = lex.REGIMATCH
const REGNAMESPACE = lex.REGNAMESPACE
const REGPROC = lex.REGPROC
const REGPROCEDURE = lex.REGPROCEDURE
const REGTYPE = lex.REGTYPE
const REINDEX = lex.REINDEX
const RELEASE = lex.RELEASE
const REMOVE_PATH = lex.REMOVE_PATH
const RENAME = lex.RENAME
const REPEATABLE = lex.REPEATABLE
const REPLACE = lex.REPLACE
const RESET = lex.RESET
const RESTORE = lex.RESTORE
const RESTRICT = lex.RESTRICT
const RESUME = lex.RESUME
const RETURNING = lex.RETURNING
const REVOKE = lex.REVOKE
const RIGHT = lex.RIGHT
const ROLE = lex.ROLE
const ROLES = lex.ROLES
const ROLLBACK = lex.ROLLBACK
const ROLLUP = lex.ROLLUP
const ROW = lex.ROW
const ROWS = lex.ROWS
const RSHIFT = lex.RSHIFT
const RULE = lex.RULE
const SAVEPOINT = lex.SAVEPOINT
const SCATTER = lex.SCATTER
const SCHEMA = lex.SCHEMA
const SCHEMAS = lex.SCHEMAS
const SCONST = lex.SCONST
const SCRUB = lex.SCRUB
const SEARCH = lex.SEARCH
const SECOND = lex.SECOND
const SELECT = lex.SELECT
const SEQUENCE = lex.SEQUENCE
const SEQUENCES = lex.SEQUENCES
const SERIAL = lex.SERIAL
const SERIAL2 = lex.SERIAL2
const SERIAL4 = lex.SERIAL4
const SERIAL8 = lex.SERIAL8
const SERIALIZABLE = lex.SERIALIZABLE
const SERVER = lex.SERVER
const SESSION = lex.SESSION
const SESSIONS = lex.SESSIONS
const SESSION_USER = lex.SESSION_USER
const SET = lex.SET
const SETTING = lex.SETTING
const SETTINGS = lex.SETTINGS
const SHARE = lex.SHARE
const SHOW = lex.SHOW
const SIMILAR = lex.SIMILAR
const SIMPLE = lex.SIMPLE
const SKIP = lex.SKIP
const SMALLINT = lex.SMALLINT
const SMALLSERIAL = lex.SMALLSERIAL
const SNAPSHOT = lex.SNAPSHOT
const SOME = lex.SOME
const SPLIT = lex.SPLIT
const SQL = lex.SQL
const START = lex.START
const STATISTICS = lex.STATISTICS
const STATUS = lex.STATUS
const STDIN = lex.STDIN
const STORE = lex.STORE
const STORED = lex.STORED
const STORING = lex.STORING
const STRICT = lex.STRICT
const STRING = lex.STRING
const SUBSCRIPTION = lex.SUBSCRIPTION
const SUBSTRING = lex.SUBSTRING
const SYMMETRIC = lex.SYMMETRIC
const SYNTAX = lex.SYNTAX
const SYSTEM = lex.SYSTEM
const TABLE = lex.TABLE
const TABLES = lex.TABLES
const TEMP = lex.TEMP
const TEMPLATE = lex.TEMPLATE
const TEMPORARY = lex.TEMPORARY
const TESTING_RELOCATE = lex.TESTING_RELOCATE
const TEXT = lex.TEXT
const THEN = lex.THEN
const THROTTLING = lex.THROTTLING
const TIES = lex.TIES
const TIME = lex.TIME
const TIMESTAMP = lex.TIMESTAMP
const TIMESTAMPTZ = lex.TIMESTAMPTZ
const TIMETZ = lex.TIMETZ
const TO = lex.TO
const TRACE = lex.TRACE
const TRACING = lex.TRACING
const TRAILING = lex.TRAILING
const TRANSACTION = lex.TRANSACTION
const TREAT = lex.TREAT
const TRIGGER = lex.TRIGGER
const TRIM = lex.TRIM
const TRUE = lex.TRUE
const TRUNCATE = lex.TRUNCATE
const TRUSTED = lex.TRUSTED
const TYPE = lex.TYPE
const TYPEANNOTATE = lex.TYPEANNOTATE
const TYPECAST = lex.TYPECAST
const UMINUS = lex.UMINUS
const UNBOUNDED = lex.UNBOUNDED
const UNCOMMITTED = lex.UNCOMMITTED
const UNION = lex.UNION
const UNIQUE = lex.UNIQUE
const UNKNOWN = lex.UNKNOWN
const UNLOGGED = lex.UNLOGGED
const UNSPLIT = lex.UNSPLIT
const UNTIL = lex.UNTIL
const UPDATE = lex.UPDATE
const UPSERT = lex.UPSERT
const USE = lex.USE
const USER = lex.USER
const USERS = lex.USERS
const USING = lex.USING
const UUID = lex.UUID
const VALID = lex.VALID
const VALIDATE = lex.VALIDATE
const VALUE = lex.VALUE
const VALUES = lex.VALUES
const VARBIT = lex.VARBIT
const VARCHAR = lex.VARCHAR
const VARIADIC = lex.VARIADIC
const VARYING = lex.VARYING
const VIEW = lex.VIEW
const VIRTUAL = lex.VIRTUAL
const WHEN = lex.WHEN
const WHERE = lex.WHERE
const WINDOW = lex.WINDOW
const WITH = lex.WITH
const WITHIN = lex.WITHIN
const WITHOUT = lex.WITHOUT
const WITH_LA = lex.WITH_LA
const WORK = lex.WORK
const WRITE = lex.WRITE
const YEAR = lex.YEAR
const ZONE = lex.ZONE
Variables ¶
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.
var DocsURLBase = "https://www.cockroachlabs.com/docs/" + "v20.1.11"
DocsURLBase is the root URL for the version of the docs associated with this binary.
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", DocsURLBase, -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 DocsURL ¶
DocsURL generates the URL to pageName in the version of the docs associated with this binary.
func EndsInSemicolon ¶
EndsInSemicolon returns true if the last lexical token is a semicolon.
func LastLexicalToken ¶
LastLexicalToken returns the last lexical token. If the string has no lexical tokens, returns 0 and ok=false.
func ParseExprs ¶
ParseExprs is a short-hand for parseExprs(sql)
func ParseQualifiedTableName ¶
ParseQualifiedTableName parses a SQL string of the form `[ database_name . ] [ schema_name . ] table_name`.
func ParseTableName ¶
func ParseTableName(sql string) (*tree.UnresolvedObjectName, error)
ParseTableName parses a table name.
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 ¶
SplitFirstStatement returns the length of the prefix of the string up to and 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 ¶
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 ¶
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 ¶
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.
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 ¶
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.