gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1334 line
35KB

  1. /*-------------------------------------------------------------------------
  2. *
  3. * plpgsql.h - Definitions for the PL/pgSQL
  4. * procedural language
  5. *
  6. * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
  7. * Portions Copyright (c) 1994, Regents of the University of California
  8. *
  9. *
  10. * IDENTIFICATION
  11. * src/pl/plpgsql/src/plpgsql.h
  12. *
  13. *-------------------------------------------------------------------------
  14. */
  15. #ifndef PLPGSQL_H
  16. #define PLPGSQL_H
  17. #include "access/xact.h"
  18. #include "commands/event_trigger.h"
  19. #include "commands/trigger.h"
  20. #include "executor/spi.h"
  21. #include "utils/expandedrecord.h"
  22. #include "utils/typcache.h"
  23. /**********************************************************************
  24. * Definitions
  25. **********************************************************************/
  26. /* define our text domain for translations */
  27. #undef TEXTDOMAIN
  28. #define TEXTDOMAIN PG_TEXTDOMAIN("plpgsql")
  29. #undef _
  30. #define _(x) dgettext(TEXTDOMAIN, x)
  31. /*
  32. * Compiler's namespace item types
  33. */
  34. typedef enum PLpgSQL_nsitem_type
  35. {
  36. PLPGSQL_NSTYPE_LABEL, /* block label */
  37. PLPGSQL_NSTYPE_VAR, /* scalar variable */
  38. PLPGSQL_NSTYPE_REC /* composite variable */
  39. } PLpgSQL_nsitem_type;
  40. /*
  41. * A PLPGSQL_NSTYPE_LABEL stack entry must be one of these types
  42. */
  43. typedef enum PLpgSQL_label_type
  44. {
  45. PLPGSQL_LABEL_BLOCK, /* DECLARE/BEGIN block */
  46. PLPGSQL_LABEL_LOOP, /* looping construct */
  47. PLPGSQL_LABEL_OTHER /* anything else */
  48. } PLpgSQL_label_type;
  49. /*
  50. * Datum array node types
  51. */
  52. typedef enum PLpgSQL_datum_type
  53. {
  54. PLPGSQL_DTYPE_VAR,
  55. PLPGSQL_DTYPE_ROW,
  56. PLPGSQL_DTYPE_REC,
  57. PLPGSQL_DTYPE_RECFIELD,
  58. PLPGSQL_DTYPE_ARRAYELEM,
  59. PLPGSQL_DTYPE_PROMISE
  60. } PLpgSQL_datum_type;
  61. /*
  62. * DTYPE_PROMISE datums have these possible ways of computing the promise
  63. */
  64. typedef enum PLpgSQL_promise_type
  65. {
  66. PLPGSQL_PROMISE_NONE = 0, /* not a promise, or promise satisfied */
  67. PLPGSQL_PROMISE_TG_NAME,
  68. PLPGSQL_PROMISE_TG_WHEN,
  69. PLPGSQL_PROMISE_TG_LEVEL,
  70. PLPGSQL_PROMISE_TG_OP,
  71. PLPGSQL_PROMISE_TG_RELID,
  72. PLPGSQL_PROMISE_TG_TABLE_NAME,
  73. PLPGSQL_PROMISE_TG_TABLE_SCHEMA,
  74. PLPGSQL_PROMISE_TG_NARGS,
  75. PLPGSQL_PROMISE_TG_ARGV,
  76. PLPGSQL_PROMISE_TG_EVENT,
  77. PLPGSQL_PROMISE_TG_TAG
  78. } PLpgSQL_promise_type;
  79. /*
  80. * Variants distinguished in PLpgSQL_type structs
  81. */
  82. typedef enum PLpgSQL_type_type
  83. {
  84. PLPGSQL_TTYPE_SCALAR, /* scalar types and domains */
  85. PLPGSQL_TTYPE_REC, /* composite types, including RECORD */
  86. PLPGSQL_TTYPE_PSEUDO /* pseudotypes */
  87. } PLpgSQL_type_type;
  88. /*
  89. * Execution tree node types
  90. */
  91. typedef enum PLpgSQL_stmt_type
  92. {
  93. PLPGSQL_STMT_BLOCK,
  94. PLPGSQL_STMT_ASSIGN,
  95. PLPGSQL_STMT_IF,
  96. PLPGSQL_STMT_CASE,
  97. PLPGSQL_STMT_LOOP,
  98. PLPGSQL_STMT_WHILE,
  99. PLPGSQL_STMT_FORI,
  100. PLPGSQL_STMT_FORS,
  101. PLPGSQL_STMT_FORC,
  102. PLPGSQL_STMT_FOREACH_A,
  103. PLPGSQL_STMT_EXIT,
  104. PLPGSQL_STMT_RETURN,
  105. PLPGSQL_STMT_RETURN_NEXT,
  106. PLPGSQL_STMT_RETURN_QUERY,
  107. PLPGSQL_STMT_RAISE,
  108. PLPGSQL_STMT_ASSERT,
  109. PLPGSQL_STMT_EXECSQL,
  110. PLPGSQL_STMT_DYNEXECUTE,
  111. PLPGSQL_STMT_DYNFORS,
  112. PLPGSQL_STMT_GETDIAG,
  113. PLPGSQL_STMT_OPEN,
  114. PLPGSQL_STMT_FETCH,
  115. PLPGSQL_STMT_CLOSE,
  116. PLPGSQL_STMT_PERFORM,
  117. PLPGSQL_STMT_CALL,
  118. PLPGSQL_STMT_COMMIT,
  119. PLPGSQL_STMT_ROLLBACK,
  120. PLPGSQL_STMT_SET
  121. } PLpgSQL_stmt_type;
  122. /*
  123. * Execution node return codes
  124. */
  125. enum
  126. {
  127. PLPGSQL_RC_OK,
  128. PLPGSQL_RC_EXIT,
  129. PLPGSQL_RC_RETURN,
  130. PLPGSQL_RC_CONTINUE
  131. };
  132. /*
  133. * GET DIAGNOSTICS information items
  134. */
  135. typedef enum PLpgSQL_getdiag_kind
  136. {
  137. PLPGSQL_GETDIAG_ROW_COUNT,
  138. PLPGSQL_GETDIAG_CONTEXT,
  139. PLPGSQL_GETDIAG_ERROR_CONTEXT,
  140. PLPGSQL_GETDIAG_ERROR_DETAIL,
  141. PLPGSQL_GETDIAG_ERROR_HINT,
  142. PLPGSQL_GETDIAG_RETURNED_SQLSTATE,
  143. PLPGSQL_GETDIAG_COLUMN_NAME,
  144. PLPGSQL_GETDIAG_CONSTRAINT_NAME,
  145. PLPGSQL_GETDIAG_DATATYPE_NAME,
  146. PLPGSQL_GETDIAG_MESSAGE_TEXT,
  147. PLPGSQL_GETDIAG_TABLE_NAME,
  148. PLPGSQL_GETDIAG_SCHEMA_NAME
  149. } PLpgSQL_getdiag_kind;
  150. /*
  151. * RAISE statement options
  152. */
  153. typedef enum PLpgSQL_raise_option_type
  154. {
  155. PLPGSQL_RAISEOPTION_ERRCODE,
  156. PLPGSQL_RAISEOPTION_MESSAGE,
  157. PLPGSQL_RAISEOPTION_DETAIL,
  158. PLPGSQL_RAISEOPTION_HINT,
  159. PLPGSQL_RAISEOPTION_COLUMN,
  160. PLPGSQL_RAISEOPTION_CONSTRAINT,
  161. PLPGSQL_RAISEOPTION_DATATYPE,
  162. PLPGSQL_RAISEOPTION_TABLE,
  163. PLPGSQL_RAISEOPTION_SCHEMA
  164. } PLpgSQL_raise_option_type;
  165. /*
  166. * Behavioral modes for plpgsql variable resolution
  167. */
  168. typedef enum PLpgSQL_resolve_option
  169. {
  170. PLPGSQL_RESOLVE_ERROR, /* throw error if ambiguous */
  171. PLPGSQL_RESOLVE_VARIABLE, /* prefer plpgsql var to table column */
  172. PLPGSQL_RESOLVE_COLUMN /* prefer table column to plpgsql var */
  173. } PLpgSQL_resolve_option;
  174. /**********************************************************************
  175. * Node and structure definitions
  176. **********************************************************************/
  177. /*
  178. * Postgres data type
  179. */
  180. typedef struct PLpgSQL_type
  181. {
  182. char *typname; /* (simple) name of the type */
  183. Oid typoid; /* OID of the data type */
  184. PLpgSQL_type_type ttype; /* PLPGSQL_TTYPE_ code */
  185. int16 typlen; /* stuff copied from its pg_type entry */
  186. bool typbyval;
  187. char typtype;
  188. Oid collation; /* from pg_type, but can be overridden */
  189. bool typisarray; /* is "true" array, or domain over one */
  190. int32 atttypmod; /* typmod (taken from someplace else) */
  191. /* Remaining fields are used only for named composite types (not RECORD) */
  192. TypeName *origtypname; /* type name as written by user */
  193. TypeCacheEntry *tcache; /* typcache entry for composite type */
  194. uint64 tupdesc_id; /* last-seen tupdesc identifier */
  195. } PLpgSQL_type;
  196. /*
  197. * SQL Query to plan and execute
  198. */
  199. typedef struct PLpgSQL_expr
  200. {
  201. char *query;
  202. SPIPlanPtr plan;
  203. Bitmapset *paramnos; /* all dnos referenced by this query */
  204. int rwparam; /* dno of read/write param, or -1 if none */
  205. /* function containing this expr (not set until we first parse query) */
  206. struct PLpgSQL_function *func;
  207. /* namespace chain visible to this expr */
  208. struct PLpgSQL_nsitem *ns;
  209. /* fields for "simple expression" fast-path execution: */
  210. Expr *expr_simple_expr; /* NULL means not a simple expr */
  211. int expr_simple_generation; /* plancache generation we checked */
  212. Oid expr_simple_type; /* result type Oid, if simple */
  213. int32 expr_simple_typmod; /* result typmod, if simple */
  214. /*
  215. * if expr is simple AND prepared in current transaction,
  216. * expr_simple_state and expr_simple_in_use are valid. Test validity by
  217. * seeing if expr_simple_lxid matches current LXID. (If not,
  218. * expr_simple_state probably points at garbage!)
  219. */
  220. ExprState *expr_simple_state; /* eval tree for expr_simple_expr */
  221. bool expr_simple_in_use; /* true if eval tree is active */
  222. LocalTransactionId expr_simple_lxid;
  223. } PLpgSQL_expr;
  224. /*
  225. * Generic datum array item
  226. *
  227. * PLpgSQL_datum is the common supertype for PLpgSQL_var, PLpgSQL_row,
  228. * PLpgSQL_rec, PLpgSQL_recfield, and PLpgSQL_arrayelem.
  229. */
  230. typedef struct PLpgSQL_datum
  231. {
  232. PLpgSQL_datum_type dtype;
  233. int dno;
  234. } PLpgSQL_datum;
  235. /*
  236. * Scalar or composite variable
  237. *
  238. * The variants PLpgSQL_var, PLpgSQL_row, and PLpgSQL_rec share these
  239. * fields.
  240. */
  241. typedef struct PLpgSQL_variable
  242. {
  243. PLpgSQL_datum_type dtype;
  244. int dno;
  245. char *refname;
  246. int lineno;
  247. bool isconst;
  248. bool notnull;
  249. PLpgSQL_expr *default_val;
  250. } PLpgSQL_variable;
  251. /*
  252. * Scalar variable
  253. *
  254. * DTYPE_VAR and DTYPE_PROMISE datums both use this struct type.
  255. * A PROMISE datum works exactly like a VAR datum for most purposes,
  256. * but if it is read without having previously been assigned to, then
  257. * a special "promised" value is computed and assigned to the datum
  258. * before the read is performed. This technique avoids the overhead of
  259. * computing the variable's value in cases where we expect that many
  260. * functions will never read it.
  261. */
  262. typedef struct PLpgSQL_var
  263. {
  264. PLpgSQL_datum_type dtype;
  265. int dno;
  266. char *refname;
  267. int lineno;
  268. bool isconst;
  269. bool notnull;
  270. PLpgSQL_expr *default_val;
  271. /* end of PLpgSQL_variable fields */
  272. PLpgSQL_type *datatype;
  273. /*
  274. * Variables declared as CURSOR FOR <query> are mostly like ordinary
  275. * scalar variables of type refcursor, but they have these additional
  276. * properties:
  277. */
  278. PLpgSQL_expr *cursor_explicit_expr;
  279. int cursor_explicit_argrow;
  280. int cursor_options;
  281. /* Fields below here can change at runtime */
  282. Datum value;
  283. bool isnull;
  284. bool freeval;
  285. /*
  286. * The promise field records which "promised" value to assign if the
  287. * promise must be honored. If it's a normal variable, or the promise has
  288. * been fulfilled, this is PLPGSQL_PROMISE_NONE.
  289. */
  290. PLpgSQL_promise_type promise;
  291. } PLpgSQL_var;
  292. /*
  293. * Row variable - this represents one or more variables that are listed in an
  294. * INTO clause, FOR-loop targetlist, cursor argument list, etc. We also use
  295. * a row to represent a function's OUT parameters when there's more than one.
  296. *
  297. * Note that there's no way to name the row as such from PL/pgSQL code,
  298. * so many functions don't need to support these.
  299. *
  300. * That also means that there's no real name for the row variable, so we
  301. * conventionally set refname to "(unnamed row)". We could leave it NULL,
  302. * but it's too convenient to be able to assume that refname is valid in
  303. * all variants of PLpgSQL_variable.
  304. *
  305. * isconst, notnull, and default_val are unsupported (and hence
  306. * always zero/null) for a row. The member variables of a row should have
  307. * been checked to be writable at compile time, so isconst is correctly set
  308. * to false. notnull and default_val aren't applicable.
  309. */
  310. typedef struct PLpgSQL_row
  311. {
  312. PLpgSQL_datum_type dtype;
  313. int dno;
  314. char *refname;
  315. int lineno;
  316. bool isconst;
  317. bool notnull;
  318. PLpgSQL_expr *default_val;
  319. /* end of PLpgSQL_variable fields */
  320. /*
  321. * rowtupdesc is only set up if we might need to convert the row into a
  322. * composite datum, which currently only happens for OUT parameters.
  323. * Otherwise it is NULL.
  324. */
  325. TupleDesc rowtupdesc;
  326. int nfields;
  327. char **fieldnames;
  328. int *varnos;
  329. } PLpgSQL_row;
  330. /*
  331. * Record variable (any composite type, including RECORD)
  332. */
  333. typedef struct PLpgSQL_rec
  334. {
  335. PLpgSQL_datum_type dtype;
  336. int dno;
  337. char *refname;
  338. int lineno;
  339. bool isconst;
  340. bool notnull;
  341. PLpgSQL_expr *default_val;
  342. /* end of PLpgSQL_variable fields */
  343. /*
  344. * Note: for non-RECORD cases, we may from time to time re-look-up the
  345. * composite type, using datatype->origtypname. That can result in
  346. * changing rectypeid.
  347. */
  348. PLpgSQL_type *datatype; /* can be NULL, if rectypeid is RECORDOID */
  349. Oid rectypeid; /* declared type of variable */
  350. /* RECFIELDs for this record are chained together for easy access */
  351. int firstfield; /* dno of first RECFIELD, or -1 if none */
  352. /* Fields below here can change at runtime */
  353. /* We always store record variables as "expanded" records */
  354. ExpandedRecordHeader *erh;
  355. } PLpgSQL_rec;
  356. /*
  357. * Field in record
  358. */
  359. typedef struct PLpgSQL_recfield
  360. {
  361. PLpgSQL_datum_type dtype;
  362. int dno;
  363. /* end of PLpgSQL_datum fields */
  364. char *fieldname; /* name of field */
  365. int recparentno; /* dno of parent record */
  366. int nextfield; /* dno of next child, or -1 if none */
  367. uint64 rectupledescid; /* record's tupledesc ID as of last lookup */
  368. ExpandedRecordFieldInfo finfo; /* field's attnum and type info */
  369. /* if rectupledescid == INVALID_TUPLEDESC_IDENTIFIER, finfo isn't valid */
  370. } PLpgSQL_recfield;
  371. /*
  372. * Element of array variable
  373. */
  374. typedef struct PLpgSQL_arrayelem
  375. {
  376. PLpgSQL_datum_type dtype;
  377. int dno;
  378. /* end of PLpgSQL_datum fields */
  379. PLpgSQL_expr *subscript;
  380. int arrayparentno; /* dno of parent array variable */
  381. /* Remaining fields are cached info about the array variable's type */
  382. Oid parenttypoid; /* type of array variable; 0 if not yet set */
  383. int32 parenttypmod; /* typmod of array variable */
  384. Oid arraytypoid; /* OID of actual array type */
  385. int32 arraytypmod; /* typmod of array (and its elements too) */
  386. int16 arraytyplen; /* typlen of array type */
  387. Oid elemtypoid; /* OID of array element type */
  388. int16 elemtyplen; /* typlen of element type */
  389. bool elemtypbyval; /* element type is pass-by-value? */
  390. char elemtypalign; /* typalign of element type */
  391. } PLpgSQL_arrayelem;
  392. /*
  393. * Item in the compilers namespace tree
  394. */
  395. typedef struct PLpgSQL_nsitem
  396. {
  397. PLpgSQL_nsitem_type itemtype;
  398. /*
  399. * For labels, itemno is a value of enum PLpgSQL_label_type. For other
  400. * itemtypes, itemno is the associated PLpgSQL_datum's dno.
  401. */
  402. int itemno;
  403. struct PLpgSQL_nsitem *prev;
  404. char name[FLEXIBLE_ARRAY_MEMBER]; /* nul-terminated string */
  405. } PLpgSQL_nsitem;
  406. /*
  407. * Generic execution node
  408. */
  409. typedef struct PLpgSQL_stmt
  410. {
  411. PLpgSQL_stmt_type cmd_type;
  412. int lineno;
  413. /*
  414. * Unique statement ID in this function (starting at 1; 0 is invalid/not
  415. * set). This can be used by a profiler as the index for an array of
  416. * per-statement metrics.
  417. */
  418. unsigned int stmtid;
  419. } PLpgSQL_stmt;
  420. /*
  421. * One EXCEPTION condition name
  422. */
  423. typedef struct PLpgSQL_condition
  424. {
  425. int sqlerrstate; /* SQLSTATE code */
  426. char *condname; /* condition name (for debugging) */
  427. struct PLpgSQL_condition *next;
  428. } PLpgSQL_condition;
  429. /*
  430. * EXCEPTION block
  431. */
  432. typedef struct PLpgSQL_exception_block
  433. {
  434. int sqlstate_varno;
  435. int sqlerrm_varno;
  436. List *exc_list; /* List of WHEN clauses */
  437. } PLpgSQL_exception_block;
  438. /*
  439. * One EXCEPTION ... WHEN clause
  440. */
  441. typedef struct PLpgSQL_exception
  442. {
  443. int lineno;
  444. PLpgSQL_condition *conditions;
  445. List *action; /* List of statements */
  446. } PLpgSQL_exception;
  447. /*
  448. * Block of statements
  449. */
  450. typedef struct PLpgSQL_stmt_block
  451. {
  452. PLpgSQL_stmt_type cmd_type;
  453. int lineno;
  454. unsigned int stmtid;
  455. char *label;
  456. List *body; /* List of statements */
  457. int n_initvars; /* Length of initvarnos[] */
  458. int *initvarnos; /* dnos of variables declared in this block */
  459. PLpgSQL_exception_block *exceptions;
  460. } PLpgSQL_stmt_block;
  461. /*
  462. * Assign statement
  463. */
  464. typedef struct PLpgSQL_stmt_assign
  465. {
  466. PLpgSQL_stmt_type cmd_type;
  467. int lineno;
  468. unsigned int stmtid;
  469. int varno;
  470. PLpgSQL_expr *expr;
  471. } PLpgSQL_stmt_assign;
  472. /*
  473. * PERFORM statement
  474. */
  475. typedef struct PLpgSQL_stmt_perform
  476. {
  477. PLpgSQL_stmt_type cmd_type;
  478. int lineno;
  479. unsigned int stmtid;
  480. PLpgSQL_expr *expr;
  481. } PLpgSQL_stmt_perform;
  482. /*
  483. * CALL statement
  484. */
  485. typedef struct PLpgSQL_stmt_call
  486. {
  487. PLpgSQL_stmt_type cmd_type;
  488. int lineno;
  489. unsigned int stmtid;
  490. PLpgSQL_expr *expr;
  491. bool is_call;
  492. PLpgSQL_variable *target;
  493. } PLpgSQL_stmt_call;
  494. /*
  495. * COMMIT statement
  496. */
  497. typedef struct PLpgSQL_stmt_commit
  498. {
  499. PLpgSQL_stmt_type cmd_type;
  500. int lineno;
  501. unsigned int stmtid;
  502. bool chain;
  503. } PLpgSQL_stmt_commit;
  504. /*
  505. * ROLLBACK statement
  506. */
  507. typedef struct PLpgSQL_stmt_rollback
  508. {
  509. PLpgSQL_stmt_type cmd_type;
  510. int lineno;
  511. unsigned int stmtid;
  512. bool chain;
  513. } PLpgSQL_stmt_rollback;
  514. /*
  515. * SET statement
  516. */
  517. typedef struct PLpgSQL_stmt_set
  518. {
  519. PLpgSQL_stmt_type cmd_type;
  520. int lineno;
  521. unsigned int stmtid;
  522. PLpgSQL_expr *expr;
  523. } PLpgSQL_stmt_set;
  524. /*
  525. * GET DIAGNOSTICS item
  526. */
  527. typedef struct PLpgSQL_diag_item
  528. {
  529. PLpgSQL_getdiag_kind kind; /* id for diagnostic value desired */
  530. int target; /* where to assign it */
  531. } PLpgSQL_diag_item;
  532. /*
  533. * GET DIAGNOSTICS statement
  534. */
  535. typedef struct PLpgSQL_stmt_getdiag
  536. {
  537. PLpgSQL_stmt_type cmd_type;
  538. int lineno;
  539. unsigned int stmtid;
  540. bool is_stacked; /* STACKED or CURRENT diagnostics area? */
  541. List *diag_items; /* List of PLpgSQL_diag_item */
  542. } PLpgSQL_stmt_getdiag;
  543. /*
  544. * IF statement
  545. */
  546. typedef struct PLpgSQL_stmt_if
  547. {
  548. PLpgSQL_stmt_type cmd_type;
  549. int lineno;
  550. unsigned int stmtid;
  551. PLpgSQL_expr *cond; /* boolean expression for THEN */
  552. List *then_body; /* List of statements */
  553. List *elsif_list; /* List of PLpgSQL_if_elsif structs */
  554. List *else_body; /* List of statements */
  555. } PLpgSQL_stmt_if;
  556. /*
  557. * one ELSIF arm of IF statement
  558. */
  559. typedef struct PLpgSQL_if_elsif
  560. {
  561. int lineno;
  562. PLpgSQL_expr *cond; /* boolean expression for this case */
  563. List *stmts; /* List of statements */
  564. } PLpgSQL_if_elsif;
  565. /*
  566. * CASE statement
  567. */
  568. typedef struct PLpgSQL_stmt_case
  569. {
  570. PLpgSQL_stmt_type cmd_type;
  571. int lineno;
  572. unsigned int stmtid;
  573. PLpgSQL_expr *t_expr; /* test expression, or NULL if none */
  574. int t_varno; /* var to store test expression value into */
  575. List *case_when_list; /* List of PLpgSQL_case_when structs */
  576. bool have_else; /* flag needed because list could be empty */
  577. List *else_stmts; /* List of statements */
  578. } PLpgSQL_stmt_case;
  579. /*
  580. * one arm of CASE statement
  581. */
  582. typedef struct PLpgSQL_case_when
  583. {
  584. int lineno;
  585. PLpgSQL_expr *expr; /* boolean expression for this case */
  586. List *stmts; /* List of statements */
  587. } PLpgSQL_case_when;
  588. /*
  589. * Unconditional LOOP statement
  590. */
  591. typedef struct PLpgSQL_stmt_loop
  592. {
  593. PLpgSQL_stmt_type cmd_type;
  594. int lineno;
  595. unsigned int stmtid;
  596. char *label;
  597. List *body; /* List of statements */
  598. } PLpgSQL_stmt_loop;
  599. /*
  600. * WHILE cond LOOP statement
  601. */
  602. typedef struct PLpgSQL_stmt_while
  603. {
  604. PLpgSQL_stmt_type cmd_type;
  605. int lineno;
  606. unsigned int stmtid;
  607. char *label;
  608. PLpgSQL_expr *cond;
  609. List *body; /* List of statements */
  610. } PLpgSQL_stmt_while;
  611. /*
  612. * FOR statement with integer loopvar
  613. */
  614. typedef struct PLpgSQL_stmt_fori
  615. {
  616. PLpgSQL_stmt_type cmd_type;
  617. int lineno;
  618. unsigned int stmtid;
  619. char *label;
  620. PLpgSQL_var *var;
  621. PLpgSQL_expr *lower;
  622. PLpgSQL_expr *upper;
  623. PLpgSQL_expr *step; /* NULL means default (ie, BY 1) */
  624. int reverse;
  625. List *body; /* List of statements */
  626. } PLpgSQL_stmt_fori;
  627. /*
  628. * PLpgSQL_stmt_forq represents a FOR statement running over a SQL query.
  629. * It is the common supertype of PLpgSQL_stmt_fors, PLpgSQL_stmt_forc
  630. * and PLpgSQL_dynfors.
  631. */
  632. typedef struct PLpgSQL_stmt_forq
  633. {
  634. PLpgSQL_stmt_type cmd_type;
  635. int lineno;
  636. unsigned int stmtid;
  637. char *label;
  638. PLpgSQL_variable *var; /* Loop variable (record or row) */
  639. List *body; /* List of statements */
  640. } PLpgSQL_stmt_forq;
  641. /*
  642. * FOR statement running over SELECT
  643. */
  644. typedef struct PLpgSQL_stmt_fors
  645. {
  646. PLpgSQL_stmt_type cmd_type;
  647. int lineno;
  648. unsigned int stmtid;
  649. char *label;
  650. PLpgSQL_variable *var; /* Loop variable (record or row) */
  651. List *body; /* List of statements */
  652. /* end of fields that must match PLpgSQL_stmt_forq */
  653. PLpgSQL_expr *query;
  654. } PLpgSQL_stmt_fors;
  655. /*
  656. * FOR statement running over cursor
  657. */
  658. typedef struct PLpgSQL_stmt_forc
  659. {
  660. PLpgSQL_stmt_type cmd_type;
  661. int lineno;
  662. unsigned int stmtid;
  663. char *label;
  664. PLpgSQL_variable *var; /* Loop variable (record or row) */
  665. List *body; /* List of statements */
  666. /* end of fields that must match PLpgSQL_stmt_forq */
  667. int curvar;
  668. PLpgSQL_expr *argquery; /* cursor arguments if any */
  669. } PLpgSQL_stmt_forc;
  670. /*
  671. * FOR statement running over EXECUTE
  672. */
  673. typedef struct PLpgSQL_stmt_dynfors
  674. {
  675. PLpgSQL_stmt_type cmd_type;
  676. int lineno;
  677. unsigned int stmtid;
  678. char *label;
  679. PLpgSQL_variable *var; /* Loop variable (record or row) */
  680. List *body; /* List of statements */
  681. /* end of fields that must match PLpgSQL_stmt_forq */
  682. PLpgSQL_expr *query;
  683. List *params; /* USING expressions */
  684. } PLpgSQL_stmt_dynfors;
  685. /*
  686. * FOREACH item in array loop
  687. */
  688. typedef struct PLpgSQL_stmt_foreach_a
  689. {
  690. PLpgSQL_stmt_type cmd_type;
  691. int lineno;
  692. unsigned int stmtid;
  693. char *label;
  694. int varno; /* loop target variable */
  695. int slice; /* slice dimension, or 0 */
  696. PLpgSQL_expr *expr; /* array expression */
  697. List *body; /* List of statements */
  698. } PLpgSQL_stmt_foreach_a;
  699. /*
  700. * OPEN a curvar
  701. */
  702. typedef struct PLpgSQL_stmt_open
  703. {
  704. PLpgSQL_stmt_type cmd_type;
  705. int lineno;
  706. unsigned int stmtid;
  707. int curvar;
  708. int cursor_options;
  709. PLpgSQL_expr *argquery;
  710. PLpgSQL_expr *query;
  711. PLpgSQL_expr *dynquery;
  712. List *params; /* USING expressions */
  713. } PLpgSQL_stmt_open;
  714. /*
  715. * FETCH or MOVE statement
  716. */
  717. typedef struct PLpgSQL_stmt_fetch
  718. {
  719. PLpgSQL_stmt_type cmd_type;
  720. int lineno;
  721. unsigned int stmtid;
  722. PLpgSQL_variable *target; /* target (record or row) */
  723. int curvar; /* cursor variable to fetch from */
  724. FetchDirection direction; /* fetch direction */
  725. long how_many; /* count, if constant (expr is NULL) */
  726. PLpgSQL_expr *expr; /* count, if expression */
  727. bool is_move; /* is this a fetch or move? */
  728. bool returns_multiple_rows; /* can return more than one row? */
  729. } PLpgSQL_stmt_fetch;
  730. /*
  731. * CLOSE curvar
  732. */
  733. typedef struct PLpgSQL_stmt_close
  734. {
  735. PLpgSQL_stmt_type cmd_type;
  736. int lineno;
  737. unsigned int stmtid;
  738. int curvar;
  739. } PLpgSQL_stmt_close;
  740. /*
  741. * EXIT or CONTINUE statement
  742. */
  743. typedef struct PLpgSQL_stmt_exit
  744. {
  745. PLpgSQL_stmt_type cmd_type;
  746. int lineno;
  747. unsigned int stmtid;
  748. bool is_exit; /* Is this an exit or a continue? */
  749. char *label; /* NULL if it's an unlabelled EXIT/CONTINUE */
  750. PLpgSQL_expr *cond;
  751. } PLpgSQL_stmt_exit;
  752. /*
  753. * RETURN statement
  754. */
  755. typedef struct PLpgSQL_stmt_return
  756. {
  757. PLpgSQL_stmt_type cmd_type;
  758. int lineno;
  759. unsigned int stmtid;
  760. PLpgSQL_expr *expr;
  761. int retvarno;
  762. } PLpgSQL_stmt_return;
  763. /*
  764. * RETURN NEXT statement
  765. */
  766. typedef struct PLpgSQL_stmt_return_next
  767. {
  768. PLpgSQL_stmt_type cmd_type;
  769. int lineno;
  770. unsigned int stmtid;
  771. PLpgSQL_expr *expr;
  772. int retvarno;
  773. } PLpgSQL_stmt_return_next;
  774. /*
  775. * RETURN QUERY statement
  776. */
  777. typedef struct PLpgSQL_stmt_return_query
  778. {
  779. PLpgSQL_stmt_type cmd_type;
  780. int lineno;
  781. unsigned int stmtid;
  782. PLpgSQL_expr *query; /* if static query */
  783. PLpgSQL_expr *dynquery; /* if dynamic query (RETURN QUERY EXECUTE) */
  784. List *params; /* USING arguments for dynamic query */
  785. } PLpgSQL_stmt_return_query;
  786. /*
  787. * RAISE statement
  788. */
  789. typedef struct PLpgSQL_stmt_raise
  790. {
  791. PLpgSQL_stmt_type cmd_type;
  792. int lineno;
  793. unsigned int stmtid;
  794. int elog_level;
  795. char *condname; /* condition name, SQLSTATE, or NULL */
  796. char *message; /* old-style message format literal, or NULL */
  797. List *params; /* list of expressions for old-style message */
  798. List *options; /* list of PLpgSQL_raise_option */
  799. } PLpgSQL_stmt_raise;
  800. /*
  801. * RAISE statement option
  802. */
  803. typedef struct PLpgSQL_raise_option
  804. {
  805. PLpgSQL_raise_option_type opt_type;
  806. PLpgSQL_expr *expr;
  807. } PLpgSQL_raise_option;
  808. /*
  809. * ASSERT statement
  810. */
  811. typedef struct PLpgSQL_stmt_assert
  812. {
  813. PLpgSQL_stmt_type cmd_type;
  814. int lineno;
  815. unsigned int stmtid;
  816. PLpgSQL_expr *cond;
  817. PLpgSQL_expr *message;
  818. } PLpgSQL_stmt_assert;
  819. /*
  820. * Generic SQL statement to execute
  821. */
  822. typedef struct PLpgSQL_stmt_execsql
  823. {
  824. PLpgSQL_stmt_type cmd_type;
  825. int lineno;
  826. unsigned int stmtid;
  827. PLpgSQL_expr *sqlstmt;
  828. bool mod_stmt; /* is the stmt INSERT/UPDATE/DELETE? Note:
  829. * mod_stmt is set when we plan the query */
  830. bool into; /* INTO supplied? */
  831. bool strict; /* INTO STRICT flag */
  832. PLpgSQL_variable *target; /* INTO target (record or row) */
  833. } PLpgSQL_stmt_execsql;
  834. /*
  835. * Dynamic SQL string to execute
  836. */
  837. typedef struct PLpgSQL_stmt_dynexecute
  838. {
  839. PLpgSQL_stmt_type cmd_type;
  840. int lineno;
  841. unsigned int stmtid;
  842. PLpgSQL_expr *query; /* string expression */
  843. bool into; /* INTO supplied? */
  844. bool strict; /* INTO STRICT flag */
  845. PLpgSQL_variable *target; /* INTO target (record or row) */
  846. List *params; /* USING expressions */
  847. } PLpgSQL_stmt_dynexecute;
  848. /*
  849. * Hash lookup key for functions
  850. */
  851. typedef struct PLpgSQL_func_hashkey
  852. {
  853. Oid funcOid;
  854. bool isTrigger; /* true if called as a DML trigger */
  855. bool isEventTrigger; /* true if called as an event trigger */
  856. /* be careful that pad bytes in this struct get zeroed! */
  857. /*
  858. * For a trigger function, the OID of the trigger is part of the hash key
  859. * --- we want to compile the trigger function separately for each trigger
  860. * it is used with, in case the rowtype or transition table names are
  861. * different. Zero if not called as a DML trigger.
  862. */
  863. Oid trigOid;
  864. /*
  865. * We must include the input collation as part of the hash key too,
  866. * because we have to generate different plans (with different Param
  867. * collations) for different collation settings.
  868. */
  869. Oid inputCollation;
  870. /*
  871. * We include actual argument types in the hash key to support polymorphic
  872. * PLpgSQL functions. Be careful that extra positions are zeroed!
  873. */
  874. Oid argtypes[FUNC_MAX_ARGS];
  875. } PLpgSQL_func_hashkey;
  876. /*
  877. * Trigger type
  878. */
  879. typedef enum PLpgSQL_trigtype
  880. {
  881. PLPGSQL_DML_TRIGGER,
  882. PLPGSQL_EVENT_TRIGGER,
  883. PLPGSQL_NOT_TRIGGER
  884. } PLpgSQL_trigtype;
  885. /*
  886. * Complete compiled function
  887. */
  888. typedef struct PLpgSQL_function
  889. {
  890. char *fn_signature;
  891. Oid fn_oid;
  892. TransactionId fn_xmin;
  893. ItemPointerData fn_tid;
  894. PLpgSQL_trigtype fn_is_trigger;
  895. Oid fn_input_collation;
  896. PLpgSQL_func_hashkey *fn_hashkey; /* back-link to hashtable key */
  897. MemoryContext fn_cxt;
  898. Oid fn_rettype;
  899. int fn_rettyplen;
  900. bool fn_retbyval;
  901. bool fn_retistuple;
  902. bool fn_retisdomain;
  903. bool fn_retset;
  904. bool fn_readonly;
  905. char fn_prokind;
  906. int fn_nargs;
  907. int fn_argvarnos[FUNC_MAX_ARGS];
  908. int out_param_varno;
  909. int found_varno;
  910. int new_varno;
  911. int old_varno;
  912. PLpgSQL_resolve_option resolve_option;
  913. bool print_strict_params;
  914. /* extra checks */
  915. int extra_warnings;
  916. int extra_errors;
  917. /* count of statements inside function */
  918. unsigned int nstatements;
  919. /* the datums representing the function's local variables */
  920. int ndatums;
  921. PLpgSQL_datum **datums;
  922. Size copiable_size; /* space for locally instantiated datums */
  923. /* function body parsetree */
  924. PLpgSQL_stmt_block *action;
  925. /* these fields change when the function is used */
  926. struct PLpgSQL_execstate *cur_estate;
  927. unsigned long use_count;
  928. } PLpgSQL_function;
  929. /*
  930. * Runtime execution data
  931. */
  932. typedef struct PLpgSQL_execstate
  933. {
  934. PLpgSQL_function *func; /* function being executed */
  935. TriggerData *trigdata; /* if regular trigger, data about firing */
  936. EventTriggerData *evtrigdata; /* if event trigger, data about firing */
  937. Datum retval;
  938. bool retisnull;
  939. Oid rettype; /* type of current retval */
  940. Oid fn_rettype; /* info about declared function rettype */
  941. bool retistuple;
  942. bool retisset;
  943. bool readonly_func;
  944. bool atomic;
  945. char *exitlabel; /* the "target" label of the current EXIT or
  946. * CONTINUE stmt, if any */
  947. ErrorData *cur_error; /* current exception handler's error */
  948. Tuplestorestate *tuple_store; /* SRFs accumulate results here */
  949. TupleDesc tuple_store_desc; /* descriptor for tuples in tuple_store */
  950. MemoryContext tuple_store_cxt;
  951. ResourceOwner tuple_store_owner;
  952. ReturnSetInfo *rsi;
  953. int found_varno;
  954. /*
  955. * The datums representing the function's local variables. Some of these
  956. * are local storage in this execstate, but some just point to the shared
  957. * copy belonging to the PLpgSQL_function, depending on whether or not we
  958. * need any per-execution state for the datum's dtype.
  959. */
  960. int ndatums;
  961. PLpgSQL_datum **datums;
  962. /* context containing variable values (same as func's SPI_proc context) */
  963. MemoryContext datum_context;
  964. /*
  965. * paramLI is what we use to pass local variable values to the executor.
  966. * It does not have a ParamExternData array; we just dynamically
  967. * instantiate parameter data as needed. By convention, PARAM_EXTERN
  968. * Params have paramid equal to the dno of the referenced local variable.
  969. */
  970. ParamListInfo paramLI;
  971. /* EState to use for "simple" expression evaluation */
  972. EState *simple_eval_estate;
  973. /* lookup table to use for executing type casts */
  974. HTAB *cast_hash;
  975. MemoryContext cast_hash_context;
  976. /* memory context for statement-lifespan temporary values */
  977. MemoryContext stmt_mcontext; /* current stmt context, or NULL if none */
  978. MemoryContext stmt_mcontext_parent; /* parent of current context */
  979. /* temporary state for results from evaluation of query or expr */
  980. SPITupleTable *eval_tuptable;
  981. uint64 eval_processed;
  982. ExprContext *eval_econtext; /* for executing simple expressions */
  983. /* status information for error context reporting */
  984. PLpgSQL_stmt *err_stmt; /* current stmt */
  985. const char *err_text; /* additional state info */
  986. void *plugin_info; /* reserved for use by optional plugin */
  987. } PLpgSQL_execstate;
  988. /*
  989. * A PLpgSQL_plugin structure represents an instrumentation plugin.
  990. * To instrument PL/pgSQL, a plugin library must access the rendezvous
  991. * variable "PLpgSQL_plugin" and set it to point to a PLpgSQL_plugin struct.
  992. * Typically the struct could just be static data in the plugin library.
  993. * We expect that a plugin would do this at library load time (_PG_init()).
  994. * It must also be careful to set the rendezvous variable back to NULL
  995. * if it is unloaded (_PG_fini()).
  996. *
  997. * This structure is basically a collection of function pointers --- at
  998. * various interesting points in pl_exec.c, we call these functions
  999. * (if the pointers are non-NULL) to give the plugin a chance to watch
  1000. * what we are doing.
  1001. *
  1002. * func_setup is called when we start a function, before we've initialized
  1003. * the local variables defined by the function.
  1004. *
  1005. * func_beg is called when we start a function, after we've initialized
  1006. * the local variables.
  1007. *
  1008. * func_end is called at the end of a function.
  1009. *
  1010. * stmt_beg and stmt_end are called before and after (respectively) each
  1011. * statement.
  1012. *
  1013. * Also, immediately before any call to func_setup, PL/pgSQL fills in the
  1014. * error_callback and assign_expr fields with pointers to its own
  1015. * plpgsql_exec_error_callback and exec_assign_expr functions. This is
  1016. * a somewhat ad-hoc expedient to simplify life for debugger plugins.
  1017. */
  1018. typedef struct PLpgSQL_plugin
  1019. {
  1020. /* Function pointers set up by the plugin */
  1021. void (*func_setup) (PLpgSQL_execstate *estate, PLpgSQL_function *func);
  1022. void (*func_beg) (PLpgSQL_execstate *estate, PLpgSQL_function *func);
  1023. void (*func_end) (PLpgSQL_execstate *estate, PLpgSQL_function *func);
  1024. void (*stmt_beg) (PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt);
  1025. void (*stmt_end) (PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt);
  1026. /* Function pointers set by PL/pgSQL itself */
  1027. void (*error_callback) (void *arg);
  1028. void (*assign_expr) (PLpgSQL_execstate *estate, PLpgSQL_datum *target,
  1029. PLpgSQL_expr *expr);
  1030. } PLpgSQL_plugin;
  1031. /*
  1032. * Struct types used during parsing
  1033. */
  1034. typedef struct PLword
  1035. {
  1036. char *ident; /* palloc'd converted identifier */
  1037. bool quoted; /* Was it double-quoted? */
  1038. } PLword;
  1039. typedef struct PLcword
  1040. {
  1041. List *idents; /* composite identifiers (list of String) */
  1042. } PLcword;
  1043. typedef struct PLwdatum
  1044. {
  1045. PLpgSQL_datum *datum; /* referenced variable */
  1046. char *ident; /* valid if simple name */
  1047. bool quoted;
  1048. List *idents; /* valid if composite name */
  1049. } PLwdatum;
  1050. /**********************************************************************
  1051. * Global variable declarations
  1052. **********************************************************************/
  1053. typedef enum
  1054. {
  1055. IDENTIFIER_LOOKUP_NORMAL, /* normal processing of var names */
  1056. IDENTIFIER_LOOKUP_DECLARE, /* In DECLARE --- don't look up names */
  1057. IDENTIFIER_LOOKUP_EXPR /* In SQL expression --- special case */
  1058. } IdentifierLookup;
  1059. extern IdentifierLookup plpgsql_IdentifierLookup;
  1060. extern int plpgsql_variable_conflict;
  1061. extern bool plpgsql_print_strict_params;
  1062. extern bool plpgsql_check_asserts;
  1063. /* extra compile-time and run-time checks */
  1064. #define PLPGSQL_XCHECK_NONE 0
  1065. #define PLPGSQL_XCHECK_SHADOWVAR (1 << 1)
  1066. #define PLPGSQL_XCHECK_TOOMANYROWS (1 << 2)
  1067. #define PLPGSQL_XCHECK_STRICTMULTIASSIGNMENT (1 << 3)
  1068. #define PLPGSQL_XCHECK_ALL ((int) ~0)
  1069. extern int plpgsql_extra_warnings;
  1070. extern int plpgsql_extra_errors;
  1071. extern bool plpgsql_check_syntax;
  1072. extern bool plpgsql_DumpExecTree;
  1073. extern PLpgSQL_stmt_block *plpgsql_parse_result;
  1074. extern int plpgsql_nDatums;
  1075. extern PLpgSQL_datum **plpgsql_Datums;
  1076. extern char *plpgsql_error_funcname;
  1077. extern PLpgSQL_function *plpgsql_curr_compile;
  1078. extern MemoryContext plpgsql_compile_tmp_cxt;
  1079. extern PLpgSQL_plugin **plpgsql_plugin_ptr;
  1080. /**********************************************************************
  1081. * Function declarations
  1082. **********************************************************************/
  1083. /*
  1084. * Functions in pl_comp.c
  1085. */
  1086. extern PLpgSQL_function *plpgsql_compile(FunctionCallInfo fcinfo,
  1087. bool forValidator);
  1088. extern PLpgSQL_function *plpgsql_compile_inline(char *proc_source);
  1089. extern void plpgsql_parser_setup(struct ParseState *pstate,
  1090. PLpgSQL_expr *expr);
  1091. extern bool plpgsql_parse_word(char *word1, const char *yytxt, bool lookup,
  1092. PLwdatum *wdatum, PLword *word);
  1093. extern bool plpgsql_parse_dblword(char *word1, char *word2,
  1094. PLwdatum *wdatum, PLcword *cword);
  1095. extern bool plpgsql_parse_tripword(char *word1, char *word2, char *word3,
  1096. PLwdatum *wdatum, PLcword *cword);
  1097. extern PLpgSQL_type *plpgsql_parse_wordtype(char *ident);
  1098. extern PLpgSQL_type *plpgsql_parse_cwordtype(List *idents);
  1099. extern PLpgSQL_type *plpgsql_parse_wordrowtype(char *ident);
  1100. extern PLpgSQL_type *plpgsql_parse_cwordrowtype(List *idents);
  1101. extern PLpgSQL_type *plpgsql_build_datatype(Oid typeOid, int32 typmod,
  1102. Oid collation,
  1103. TypeName *origtypname);
  1104. extern PLpgSQL_variable *plpgsql_build_variable(const char *refname, int lineno,
  1105. PLpgSQL_type *dtype,
  1106. bool add2namespace);
  1107. extern PLpgSQL_rec *plpgsql_build_record(const char *refname, int lineno,
  1108. PLpgSQL_type *dtype, Oid rectypeid,
  1109. bool add2namespace);
  1110. extern PLpgSQL_recfield *plpgsql_build_recfield(PLpgSQL_rec *rec,
  1111. const char *fldname);
  1112. extern int plpgsql_recognize_err_condition(const char *condname,
  1113. bool allow_sqlstate);
  1114. extern PLpgSQL_condition *plpgsql_parse_err_condition(char *condname);
  1115. extern void plpgsql_adddatum(PLpgSQL_datum *newdatum);
  1116. extern int plpgsql_add_initdatums(int **varnos);
  1117. extern void plpgsql_HashTableInit(void);
  1118. /*
  1119. * Functions in pl_handler.c
  1120. */
  1121. extern void _PG_init(void);
  1122. /*
  1123. * Functions in pl_exec.c
  1124. */
  1125. extern Datum plpgsql_exec_function(PLpgSQL_function *func,
  1126. FunctionCallInfo fcinfo,
  1127. EState *simple_eval_estate,
  1128. bool atomic);
  1129. extern HeapTuple plpgsql_exec_trigger(PLpgSQL_function *func,
  1130. TriggerData *trigdata);
  1131. extern void plpgsql_exec_event_trigger(PLpgSQL_function *func,
  1132. EventTriggerData *trigdata);
  1133. extern void plpgsql_xact_cb(XactEvent event, void *arg);
  1134. extern void plpgsql_subxact_cb(SubXactEvent event, SubTransactionId mySubid,
  1135. SubTransactionId parentSubid, void *arg);
  1136. extern Oid plpgsql_exec_get_datum_type(PLpgSQL_execstate *estate,
  1137. PLpgSQL_datum *datum);
  1138. extern void plpgsql_exec_get_datum_type_info(PLpgSQL_execstate *estate,
  1139. PLpgSQL_datum *datum,
  1140. Oid *typeId, int32 *typMod,
  1141. Oid *collation);
  1142. /*
  1143. * Functions for namespace handling in pl_funcs.c
  1144. */
  1145. extern void plpgsql_ns_init(void);
  1146. extern void plpgsql_ns_push(const char *label,
  1147. PLpgSQL_label_type label_type);
  1148. extern void plpgsql_ns_pop(void);
  1149. extern PLpgSQL_nsitem *plpgsql_ns_top(void);
  1150. extern void plpgsql_ns_additem(PLpgSQL_nsitem_type itemtype, int itemno, const char *name);
  1151. extern PLpgSQL_nsitem *plpgsql_ns_lookup(PLpgSQL_nsitem *ns_cur, bool localmode,
  1152. const char *name1, const char *name2,
  1153. const char *name3, int *names_used);
  1154. extern PLpgSQL_nsitem *plpgsql_ns_lookup_label(PLpgSQL_nsitem *ns_cur,
  1155. const char *name);
  1156. extern PLpgSQL_nsitem *plpgsql_ns_find_nearest_loop(PLpgSQL_nsitem *ns_cur);
  1157. /*
  1158. * Other functions in pl_funcs.c
  1159. */
  1160. extern const char *plpgsql_stmt_typename(PLpgSQL_stmt *stmt);
  1161. extern const char *plpgsql_getdiag_kindname(PLpgSQL_getdiag_kind kind);
  1162. extern void plpgsql_free_function_memory(PLpgSQL_function *func);
  1163. extern void plpgsql_dumptree(PLpgSQL_function *func);
  1164. /*
  1165. * Scanner functions in pl_scanner.c
  1166. */
  1167. extern int plpgsql_base_yylex(void);
  1168. extern int plpgsql_yylex(void);
  1169. extern void plpgsql_push_back_token(int token);
  1170. extern bool plpgsql_token_is_unreserved_keyword(int token);
  1171. extern void plpgsql_append_source_text(StringInfo buf,
  1172. int startlocation, int endlocation);
  1173. extern int plpgsql_peek(void);
  1174. extern void plpgsql_peek2(int *tok1_p, int *tok2_p, int *tok1_loc,
  1175. int *tok2_loc);
  1176. extern int plpgsql_scanner_errposition(int location);
  1177. extern void plpgsql_yyerror(const char *message) pg_attribute_noreturn();
  1178. extern int plpgsql_location_to_lineno(int location);
  1179. extern int plpgsql_latest_lineno(void);
  1180. extern void plpgsql_scanner_init(const char *str);
  1181. extern void plpgsql_scanner_finish(void);
  1182. /*
  1183. * Externs in gram.y
  1184. */
  1185. extern int plpgsql_yyparse(void);
  1186. #endif /* PLPGSQL_H */
上海开阖软件有限公司 沪ICP备12045867号-1