Documentation
¶
Overview ¶
Package plpgsql parses PL/pgSQL function bodies into the AST defined in go/common/parser/ast. The parser is a goyacc port of postgres/src/pl/plpgsql/src/pl_gram.y and is used by the multigateway planner for Tier 1 session-state-leak detection (DO blocks, CREATE FUNCTION … LANGUAGE plpgsql).
Index ¶
Constants ¶
const ( IDENT = 57346 UIDENT = 57347 FCONST = 57348 SCONST = 57349 USCONST = 57350 BCONST = 57351 XCONST = 57352 Op = 57353 ICONST = 57354 PARAM = 57355 TYPECAST = 57356 DOT_DOT = 57357 COLON_EQUALS = 57358 EQUALS_GREATER = 57359 LESS_EQUALS = 57360 GREATER_EQUALS = 57361 NOT_EQUALS = 57362 T_WORD = 57363 T_CWORD = 57364 T_DATUM = 57365 LESS_LESS = 57366 GREATER_GREATER = 57367 K_ABSOLUTE = 57368 K_ALIAS = 57369 K_ALL = 57370 K_AND = 57371 K_ARRAY = 57372 K_ASSERT = 57373 K_BACKWARD = 57374 K_BEGIN = 57375 K_BY = 57376 K_CALL = 57377 K_CASE = 57378 K_CHAIN = 57379 K_CLOSE = 57380 K_COLLATE = 57381 K_COLUMN = 57382 K_COLUMN_NAME = 57383 K_COMMIT = 57384 K_CONSTANT = 57385 K_CONSTRAINT = 57386 K_CONSTRAINT_NAME = 57387 K_CONTINUE = 57388 K_CURRENT = 57389 K_CURSOR = 57390 K_DATATYPE = 57391 K_DEBUG = 57392 K_DECLARE = 57393 K_DEFAULT = 57394 K_DETAIL = 57395 K_DIAGNOSTICS = 57396 K_DO = 57397 K_DUMP = 57398 K_ELSE = 57399 K_ELSIF = 57400 K_END = 57401 K_ERRCODE = 57402 K_ERROR = 57403 K_EXCEPTION = 57404 K_EXECUTE = 57405 K_EXIT = 57406 K_FETCH = 57407 K_FIRST = 57408 K_FOR = 57409 K_FOREACH = 57410 K_FORWARD = 57411 K_FROM = 57412 K_GET = 57413 K_HINT = 57414 K_IF = 57415 K_IMPORT = 57416 K_IN = 57417 K_INFO = 57418 K_INSERT = 57419 K_INTO = 57420 K_IS = 57421 K_LAST = 57422 K_LOG = 57423 K_LOOP = 57424 K_MERGE = 57425 K_MESSAGE = 57426 K_MESSAGE_TEXT = 57427 K_MOVE = 57428 K_NEXT = 57429 K_NO = 57430 K_NOT = 57431 K_NOTICE = 57432 K_NULL = 57433 K_OPEN = 57434 K_OPTION = 57435 K_OR = 57436 K_PERFORM = 57437 K_PG_CONTEXT = 57438 K_PG_DATATYPE_NAME = 57439 K_PG_EXCEPTION_CONTEXT = 57440 K_PG_EXCEPTION_DETAIL = 57441 K_PG_EXCEPTION_HINT = 57442 K_PG_ROUTINE_OID = 57443 K_PRINT_STRICT_PARAMS = 57444 K_PRIOR = 57445 K_QUERY = 57446 K_RAISE = 57447 K_RELATIVE = 57448 K_RETURN = 57449 K_RETURNED_SQLSTATE = 57450 K_REVERSE = 57451 K_ROLLBACK = 57452 K_ROW_COUNT = 57453 K_ROWTYPE = 57454 K_SCHEMA = 57455 K_SCHEMA_NAME = 57456 K_SCROLL = 57457 K_SLICE = 57458 K_SQLSTATE = 57459 K_STACKED = 57460 K_STRICT = 57461 K_TABLE = 57462 K_TABLE_NAME = 57463 K_THEN = 57464 K_TO = 57465 K_TYPE = 57466 K_USE_COLUMN = 57467 K_USE_VARIABLE = 57468 K_USING = 57469 K_VARIABLE_CONFLICT = 57470 K_WARNING = 57471 K_WHEN = 57472 K_WHILE = 57473 )
Variables ¶
This section is empty.
Functions ¶
func ParsePLpgSQL ¶
func ParsePLpgSQL(body string) (*plpgsqlast.PLpgSQL_function, error)
ParsePLpgSQL parses an already-extracted PL/pgSQL function body (with dollar-quote or quoted-string delimiters stripped by the caller) and returns its AST root.
A body must be a block (BEGIN … END), matching PG; empty input is a parse error.
func ParsePLpgSQLSeeded ¶
func ParsePLpgSQLSeeded(body string, seed *ParseSeed) (*plpgsqlast.PLpgSQL_function, error)
ParsePLpgSQLSeeded is ParsePLpgSQL with a set of function-scope names pre-declared (see ParseSeed). A nil or empty seed behaves exactly like ParsePLpgSQL — the body parses in isolation.
Types ¶
type ParseSeed ¶
type ParseSeed struct {
Scalars []string // e.g. parameter names, "$1".."$N", TG_* trigger variables
Records []string // e.g. NEW / OLD in a trigger function
}
ParseSeed carries names to pre-declare in an outer (function-scope) namespace before a body is parsed. A body is parsed in isolation — without its surrounding CREATE FUNCTION signature — so names that live in the signature rather than the body's own DECLARE section (parameters, and a trigger function's implicit NEW/OLD/TG_* variables) would not resolve, and an assignment to one (`param := …`, `new.field := …`) would be misparsed as an embedded SQL statement.
PG has the whole signature at compile time, so its do_compile (pl_comp.c) builds these as datums in the function-scope namespace before parsing the body: each parameter is registered under "$N" and, if named, under its name; a DML-trigger function adds NEW/OLD as records and tg_name/tg_when/tg_level/ tg_op/tg_relid/tg_relname/tg_table_name/tg_table_schema/tg_nargs/tg_argv, and an event-trigger function adds tg_event/tg_tag. ParseSeed lets the caller, which does have the signature, hand those same names in.
Scalars are seeded as plain variables; Records (NEW/OLD) as record variables so a `rec.field` assignment target resolves. Names should be lowercased for unquoted identifiers, matching the scanner's lookup.