📄 gram.y
字号:
*****************************************************************************/ClosePortalStmt: CLOSE name { ClosePortalStmt *n = makeNode(ClosePortalStmt); n->portalname = $2; $$ = (Node *)n; } ;/***************************************************************************** * * QUERY : * COPY <relname> ['(' columnList ')'] FROM/TO [WITH options] * * BINARY, OIDS, and DELIMITERS kept in old locations * for backward compatibility. 2002-06-18 * *****************************************************************************/CopyStmt: COPY opt_binary qualified_name opt_column_list opt_oids copy_from copy_file_name copy_delimiter opt_with copy_opt_list { CopyStmt *n = makeNode(CopyStmt); n->relation = $3; n->attlist = $4; n->is_from = $6; n->filename = $7; n->options = NIL; /* Concatenate user-supplied flags */ if ($2) n->options = lappend(n->options, $2); if ($5) n->options = lappend(n->options, $5); if ($8) n->options = lappend(n->options, $8); if ($10) n->options = list_concat(n->options, $10); $$ = (Node *)n; } ;copy_from: FROM { $$ = TRUE; } | TO { $$ = FALSE; } ;/* * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is * used depends on the direction. (It really doesn't make sense to copy from * stdout. We silently correct the "typo". - AY 9/94 */copy_file_name: Sconst { $$ = $1; } | STDIN { $$ = NULL; } | STDOUT { $$ = NULL; } ;copy_opt_list: copy_opt_list copy_opt_item { $$ = lappend($1, $2); } | /* EMPTY */ { $$ = NIL; } ;copy_opt_item: BINARY { $$ = makeDefElem("binary", (Node *)makeInteger(TRUE)); } | OIDS { $$ = makeDefElem("oids", (Node *)makeInteger(TRUE)); } | DELIMITER opt_as Sconst { $$ = makeDefElem("delimiter", (Node *)makeString($3)); } | NULL_P opt_as Sconst { $$ = makeDefElem("null", (Node *)makeString($3)); } | CSV { $$ = makeDefElem("csv", (Node *)makeInteger(TRUE)); } | HEADER { $$ = makeDefElem("header", (Node *)makeInteger(TRUE)); } | QUOTE opt_as Sconst { $$ = makeDefElem("quote", (Node *)makeString($3)); } | ESCAPE opt_as Sconst { $$ = makeDefElem("escape", (Node *)makeString($3)); } | FORCE QUOTE columnList { $$ = makeDefElem("force_quote", (Node *)$3); } | FORCE NOT NULL_P columnList { $$ = makeDefElem("force_notnull", (Node *)$4); } ;/* The following exist for backward compatibility */opt_binary: BINARY { $$ = makeDefElem("binary", (Node *)makeInteger(TRUE)); } | /*EMPTY*/ { $$ = NULL; } ;opt_oids: WITH OIDS { $$ = makeDefElem("oids", (Node *)makeInteger(TRUE)); } | /*EMPTY*/ { $$ = NULL; } ;copy_delimiter: /* USING DELIMITERS kept for backward compatibility. 2002-06-15 */ opt_using DELIMITERS Sconst { $$ = makeDefElem("delimiter", (Node *)makeString($3)); } | /*EMPTY*/ { $$ = NULL; } ;opt_using: USING {} | /*EMPTY*/ {} ;/***************************************************************************** * * QUERY : * CREATE TABLE relname * *****************************************************************************/CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')' OptInherit OptWithOids OnCommitOption OptTableSpace { CreateStmt *n = makeNode(CreateStmt); $4->istemp = $2; n->relation = $4; n->tableElts = $6; n->inhRelations = $8; n->constraints = NIL; n->hasoids = $9; n->oncommit = $10; n->tablespacename = $11; $$ = (Node *)n; } | CREATE OptTemp TABLE qualified_name OF qualified_name '(' OptTableElementList ')' OptWithOids OnCommitOption OptTableSpace { /* SQL99 CREATE TABLE OF <UDT> (cols) seems to be satisfied * by our inheritance capabilities. Let's try it... */ CreateStmt *n = makeNode(CreateStmt); $4->istemp = $2; n->relation = $4; n->tableElts = $8; n->inhRelations = list_make1($6); n->constraints = NIL; n->hasoids = $10; n->oncommit = $11; n->tablespacename = $12; $$ = (Node *)n; } ;/* * Redundancy here is needed to avoid shift/reduce conflicts, * since TEMP is not a reserved word. See also OptTempTableName. * * NOTE: we accept both GLOBAL and LOCAL options; since we have no modules * the LOCAL keyword is really meaningless. */OptTemp: TEMPORARY { $$ = TRUE; } | TEMP { $$ = TRUE; } | LOCAL TEMPORARY { $$ = TRUE; } | LOCAL TEMP { $$ = TRUE; } | GLOBAL TEMPORARY { $$ = TRUE; } | GLOBAL TEMP { $$ = TRUE; } | /*EMPTY*/ { $$ = FALSE; } ;OptTableElementList: TableElementList { $$ = $1; } | /*EMPTY*/ { $$ = NIL; } ;TableElementList: TableElement { $$ = list_make1($1); } | TableElementList ',' TableElement { $$ = lappend($1, $3); } ;TableElement: columnDef { $$ = $1; } | TableLikeClause { $$ = $1; } | TableConstraint { $$ = $1; } ;columnDef: ColId Typename ColQualList { ColumnDef *n = makeNode(ColumnDef); n->colname = $1; n->typename = $2; n->constraints = $3; n->is_local = true; $$ = (Node *)n; } ;ColQualList: ColQualList ColConstraint { $$ = lappend($1, $2); } | /*EMPTY*/ { $$ = NIL; } ;ColConstraint: CONSTRAINT name ColConstraintElem { switch (nodeTag($3)) { case T_Constraint: { Constraint *n = (Constraint *)$3; n->name = $2; } break; case T_FkConstraint: { FkConstraint *n = (FkConstraint *)$3; n->constr_name = $2; } break; default: break; } $$ = $3; } | ColConstraintElem { $$ = $1; } | ConstraintAttr { $$ = $1; } ;/* DEFAULT NULL is already the default for Postgres. * But define it here and carry it forward into the system * to make it explicit. * - thomas 1998-09-13 * * WITH NULL and NULL are not SQL92-standard syntax elements, * so leave them out. Use DEFAULT NULL to explicitly indicate * that a column may have that value. WITH NULL leads to * shift/reduce conflicts with WITH TIME ZONE anyway. * - thomas 1999-01-08 * * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce * conflict on NOT (since NOT might start a subsequent NOT NULL constraint, * or be part of a_expr NOT LIKE or similar constructs). */ColConstraintElem: NOT NULL_P { Constraint *n = makeNode(Constraint); n->contype = CONSTR_NOTNULL; n->name = NULL; n->raw_expr = NULL; n->cooked_expr = NULL; n->keys = NULL; n->indexspace = NULL; $$ = (Node *)n; } | NULL_P { Constraint *n = makeNode(Constraint); n->contype = CONSTR_NULL; n->name = NULL; n->raw_expr = NULL; n->cooked_expr = NULL; n->keys = NULL; n->indexspace = NULL; $$ = (Node *)n; } | UNIQUE OptConsTableSpace { Constraint *n = makeNode(Constraint); n->contype = CONSTR_UNIQUE; n->name = NULL; n->raw_expr = NULL; n->cooked_expr = NULL; n->keys = NULL; n->indexspace = $2; $$ = (Node *)n; } | PRIMARY KEY OptConsTableSpace { Constraint *n = makeNode(Constraint); n->contype = CONSTR_PRIMARY; n->name = NULL; n->raw_expr = NULL; n->cooked_expr = NULL; n->keys = NULL; n->indexspace = $3; $$ = (Node *)n; } | CHECK '(' a_expr ')' { Constraint *n = makeNode(Constraint); n->contype = CONSTR_CHECK; n->name = NULL; n->raw_expr = $3; n->cooked_expr = NULL; n->keys = NULL; n->indexspace = NULL; $$ = (Node *)n; } | DEFAULT b_expr { Constraint *n = makeNode(Constraint); n->contype = CONSTR_DEFAULT; n->name = NULL; if (exprIsNullConstant($2)) { /* DEFAULT NULL should be reported as empty expr */ n->raw_expr = NULL; } else { n->raw_expr = $2; } n->cooked_expr = NULL; n->keys = NULL; n->indexspace = NULL; $$ = (Node *)n; } | REFERENCES qualified_name opt_column_list key_match key_actions { FkConstraint *n = makeNode(FkConstraint); n->constr_name = NULL; n->pktable = $2; n->fk_attrs = NIL; n->pk_attrs = $3; n->fk_matchtype = $4; n->fk_upd_action = (char) ($5 >> 8); n->fk_del_action = (char) ($5 & 0xFF); n->deferrable = FALSE; n->initdeferred = FALSE; $$ = (Node *)n; } ;/* * ConstraintAttr represents constraint attributes, which we parse as if * they were independent constraint clauses, in order to avoid shift/reduce * conflicts (since NOT might start either an independent NOT NULL clause * or an attribute). analyze.c is responsible for attaching the attribute * information to the preceding "real" constraint node, and for complaining * if attribute clauses appear in the wrong place or wrong combinations. * * See also ConstraintAttributeSpec, which can be used in places where * there is no parsing conflict. */ConstraintAttr: DEFERRABLE { Constraint *n = makeNode(Constraint); n->contype = CONSTR_ATTR_DEFERRABLE; $$ = (Node *)n; } | NOT DEFERRABLE { Constraint *n = makeNode(Constraint); n->contype = CONSTR_ATTR_NOT_DEFERRABLE; $$ = (Node *)n; } | INITIALLY DEFERRED { Constraint *n = makeNode(Constraint); n->contype = CONSTR_ATTR_DEFERRED; $$ = (Node *)n; } | INITIALLY IMMEDIATE { Constraint *n = makeNode(Constraint); n->contype = CONSTR_ATTR_IMMEDIATE; $$ = (Node *)n; } ;/* * SQL99 supports wholesale borrowing of a table definition via the LIKE clause. * This seems to be a poor man's inheritance capability, with the resulting * tables completely decoupled except for the original commonality in definitions. * * This is very similar to CREATE TABLE AS except for the INCLUDING DEFAULTS extension * which is a part of SQL 200N */TableLikeClause: LIKE qualified_name like_including_defaults { InhRelation *n = makeNode(InhRelation); n->relation = $2; n->including_defaults = $3; $$ = (Node *)n; } ;like_including_defaults: INCLUDING DEFAULTS { $$ = true; } | EXCLUDING DEFAULTS { $$ = false; } | /* EMPTY */ { $$ = false; } ;/* ConstraintElem specifies constraint syntax which is not embedded into * a column definition. ColConstraintElem specifies the embedded form. * - thomas 1997-12-03 */TableConstraint: CONSTRAINT name ConstraintElem { switch (nodeTag($3)) { case T_Constraint: { Constraint *n = (Constraint *)$3; n->name = $2; } break; case T_FkConstraint: { FkConstraint *n = (FkConstraint *)$3; n->constr_name = $2; } break; default: break; } $$ = $3; } | ConstraintElem { $$ = $1; } ;ConstraintElem: CHECK '(' a_expr ')' { Constraint *n = makeNode(Constraint); n->contype = CONSTR_CHECK; n->name = NULL; n->raw_expr = $3; n->cooked_expr = NULL; n->indexspace = NULL; $$ = (Node *)n; } | UNIQUE '(' columnList ')' OptConsTableSpace { Constraint *n = makeNode(Constraint); n->contype = CONSTR_UNIQUE; n->name = NULL; n->raw_expr = NULL; n->cooked_expr = NULL; n->keys = $3; n->indexspace = $5; $$ = (Node *)n; } | PRIMARY KEY '(' columnList ')' OptConsTableSpace { Constraint *n = makeNode(Constraint); n->contype = CONSTR_PRIMARY; n->name = NULL; n->raw_expr = NULL; n->cooked_expr = NULL; n->keys = $4; n->indexspace = $6; $$ = (Node *)n; } | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name opt_column_list key_match key_actions ConstraintAttributeSpec { FkConstraint *n = makeNode(FkConstraint); n->constr_name = NULL; n->pktable = $7; n->fk_attrs = $4; n->pk_attrs = $8; n->fk_matchtype = $9; n->fk_upd_action = (char) ($10 >> 8);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -