{"modulePath":"github.com/namiri-tech/pgparser","version":"v0.1.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package plpgsql\n\nPackage 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).\n\n## Constants\n\n```go\nconst (\n\tIDENT                  = 57346\n\tUIDENT                 = 57347\n\tFCONST                 = 57348\n\tSCONST                 = 57349\n\tUSCONST                = 57350\n\tBCONST                 = 57351\n\tXCONST                 = 57352\n\tOp                     = 57353\n\tICONST                 = 57354\n\tPARAM                  = 57355\n\tTYPECAST               = 57356\n\tDOT_DOT                = 57357\n\tCOLON_EQUALS           = 57358\n\tEQUALS_GREATER         = 57359\n\tLESS_EQUALS            = 57360\n\tGREATER_EQUALS         = 57361\n\tNOT_EQUALS             = 57362\n\tT_WORD                 = 57363\n\tT_CWORD                = 57364\n\tT_DATUM                = 57365\n\tLESS_LESS              = 57366\n\tGREATER_GREATER        = 57367\n\tK_ABSOLUTE             = 57368\n\tK_ALIAS                = 57369\n\tK_ALL                  = 57370\n\tK_AND                  = 57371\n\tK_ARRAY                = 57372\n\tK_ASSERT               = 57373\n\tK_BACKWARD             = 57374\n\tK_BEGIN                = 57375\n\tK_BY                   = 57376\n\tK_CALL                 = 57377\n\tK_CASE                 = 57378\n\tK_CHAIN                = 57379\n\tK_CLOSE                = 57380\n\tK_COLLATE              = 57381\n\tK_COLUMN               = 57382\n\tK_COLUMN_NAME          = 57383\n\tK_COMMIT               = 57384\n\tK_CONSTANT             = 57385\n\tK_CONSTRAINT           = 57386\n\tK_CONSTRAINT_NAME      = 57387\n\tK_CONTINUE             = 57388\n\tK_CURRENT              = 57389\n\tK_CURSOR               = 57390\n\tK_DATATYPE             = 57391\n\tK_DEBUG                = 57392\n\tK_DECLARE              = 57393\n\tK_DEFAULT              = 57394\n\tK_DETAIL               = 57395\n\tK_DIAGNOSTICS          = 57396\n\tK_DO                   = 57397\n\tK_DUMP                 = 57398\n\tK_ELSE                 = 57399\n\tK_ELSIF                = 57400\n\tK_END                  = 57401\n\tK_ERRCODE              = 57402\n\tK_ERROR                = 57403\n\tK_EXCEPTION            = 57404\n\tK_EXECUTE              = 57405\n\tK_EXIT                 = 57406\n\tK_FETCH                = 57407\n\tK_FIRST                = 57408\n\tK_FOR                  = 57409\n\tK_FOREACH              = 57410\n\tK_FORWARD              = 57411\n\tK_FROM                 = 57412\n\tK_GET                  = 57413\n\tK_HINT                 = 57414\n\tK_IF                   = 57415\n\tK_IMPORT               = 57416\n\tK_IN                   = 57417\n\tK_INFO                 = 57418\n\tK_INSERT               = 57419\n\tK_INTO                 = 57420\n\tK_IS                   = 57421\n\tK_LAST                 = 57422\n\tK_LOG                  = 57423\n\tK_LOOP                 = 57424\n\tK_MERGE                = 57425\n\tK_MESSAGE              = 57426\n\tK_MESSAGE_TEXT         = 57427\n\tK_MOVE                 = 57428\n\tK_NEXT                 = 57429\n\tK_NO                   = 57430\n\tK_NOT                  = 57431\n\tK_NOTICE               = 57432\n\tK_NULL                 = 57433\n\tK_OPEN                 = 57434\n\tK_OPTION               = 57435\n\tK_OR                   = 57436\n\tK_PERFORM              = 57437\n\tK_PG_CONTEXT           = 57438\n\tK_PG_DATATYPE_NAME     = 57439\n\tK_PG_EXCEPTION_CONTEXT = 57440\n\tK_PG_EXCEPTION_DETAIL  = 57441\n\tK_PG_EXCEPTION_HINT    = 57442\n\tK_PG_ROUTINE_OID       = 57443\n\tK_PRINT_STRICT_PARAMS  = 57444\n\tK_PRIOR                = 57445\n\tK_QUERY                = 57446\n\tK_RAISE                = 57447\n\tK_RELATIVE             = 57448\n\tK_RETURN               = 57449\n\tK_RETURNED_SQLSTATE    = 57450\n\tK_REVERSE              = 57451\n\tK_ROLLBACK             = 57452\n\tK_ROW_COUNT            = 57453\n\tK_ROWTYPE              = 57454\n\tK_SCHEMA               = 57455\n\tK_SCHEMA_NAME          = 57456\n\tK_SCROLL               = 57457\n\tK_SLICE                = 57458\n\tK_SQLSTATE             = 57459\n\tK_STACKED              = 57460\n\tK_STRICT               = 57461\n\tK_TABLE                = 57462\n\tK_TABLE_NAME           = 57463\n\tK_THEN                 = 57464\n\tK_TO                   = 57465\n\tK_TYPE                 = 57466\n\tK_USE_COLUMN           = 57467\n\tK_USE_VARIABLE         = 57468\n\tK_USING                = 57469\n\tK_VARIABLE_CONFLICT    = 57470\n\tK_WARNING              = 57471\n\tK_WHEN                 = 57472\n\tK_WHILE                = 57473\n)\n```\n\n## Functions\n\n```go\nfunc ParsePLpgSQL(body string) (*plpgsqlast.PLpgSQL_function, error)\n```\nParsePLpgSQL parses an already-extracted PL/pgSQL function body (with dollar-quote or quoted-string delimiters stripped by the caller) and returns its AST root.\n\nA body must be a block (BEGIN … END), matching PG; empty input is a parse error.\n\n```go\nfunc ParsePLpgSQLSeeded(body string, seed *ParseSeed) (*plpgsqlast.PLpgSQL_function, error)\n```\nParsePLpgSQLSeeded 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.\n\n## Types\n\n```go\ntype ParseSeed struct {\n\tScalars []string // e.g. parameter names, \"$1\"..\"$N\", TG_* trigger variables\n\tRecords []string // e.g. NEW / OLD in a trigger function\n}\n```\nParseSeed 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.\n\nPG 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.\n\nScalars 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.\n\n","path":"github.com/namiri-tech/pgparser/plpgsql","name":"plpgsql","synopsis":"Package plpgsql parses PL/pgSQL function bodies into the AST defined in go/common/parser/ast.","isRedistributable":true}
