📄 gram.y
字号:
| SHOW ALL { VariableShowStmt *n = makeNode(VariableShowStmt); n->name = "all"; $$ = (Node *) n; } ;VariableResetStmt: RESET ColId { VariableResetStmt *n = makeNode(VariableResetStmt); n->name = $2; $$ = (Node *) n; } | RESET TIME ZONE { VariableResetStmt *n = makeNode(VariableResetStmt); n->name = "timezone"; $$ = (Node *) n; } | RESET TRANSACTION ISOLATION LEVEL { VariableResetStmt *n = makeNode(VariableResetStmt); n->name = "transaction_isolation"; $$ = (Node *) n; } | RESET SESSION AUTHORIZATION { VariableResetStmt *n = makeNode(VariableResetStmt); n->name = "session_authorization"; $$ = (Node *) n; } | RESET ALL { VariableResetStmt *n = makeNode(VariableResetStmt); n->name = "all"; $$ = (Node *) n; } ;ConstraintsSetStmt: SET CONSTRAINTS constraints_set_list constraints_set_mode { ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt); n->constraints = $3; n->deferred = $4; $$ = (Node *) n; } ;constraints_set_list: ALL { $$ = NIL; } | name_list { $$ = $1; } ;constraints_set_mode: DEFERRED { $$ = TRUE; } | IMMEDIATE { $$ = FALSE; } ;/* * Checkpoint statement */CheckPointStmt: CHECKPOINT { CheckPointStmt *n = makeNode(CheckPointStmt); $$ = (Node *)n; } ;/***************************************************************************** * * ALTER TABLE variations * *****************************************************************************/AlterTableStmt: /* ALTER TABLE <relation> ADD [COLUMN] <coldef> */ ALTER TABLE relation_expr ADD opt_column columnDef { AlterTableStmt *n = makeNode(AlterTableStmt); n->subtype = 'A'; n->relation = $3; n->def = $6; $$ = (Node *)n; } /* ALTER TABLE <relation> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */ | ALTER TABLE relation_expr ALTER opt_column ColId alter_column_default { AlterTableStmt *n = makeNode(AlterTableStmt); n->subtype = 'T'; n->relation = $3; n->name = $6; n->def = $7; $$ = (Node *)n; } /* ALTER TABLE <relation> ALTER [COLUMN] <colname> DROP NOT NULL */ | ALTER TABLE relation_expr ALTER opt_column ColId DROP NOT NULL_P { AlterTableStmt *n = makeNode(AlterTableStmt); n->subtype = 'N'; n->relation = $3; n->name = $6; $$ = (Node *)n; } /* ALTER TABLE <relation> ALTER [COLUMN] <colname> SET NOT NULL */ | ALTER TABLE relation_expr ALTER opt_column ColId SET NOT NULL_P { AlterTableStmt *n = makeNode(AlterTableStmt); n->subtype = 'n'; n->relation = $3; n->name = $6; $$ = (Node *)n; } /* ALTER TABLE <relation> ALTER [COLUMN] <colname> SET STATISTICS <IntegerOnly> */ | ALTER TABLE relation_expr ALTER opt_column ColId SET STATISTICS IntegerOnly { AlterTableStmt *n = makeNode(AlterTableStmt); n->subtype = 'S'; n->relation = $3; n->name = $6; n->def = (Node *) $9; $$ = (Node *)n; } /* ALTER TABLE <relation> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */ | ALTER TABLE relation_expr ALTER opt_column ColId SET STORAGE ColId { AlterTableStmt *n = makeNode(AlterTableStmt); n->subtype = 'M'; n->relation = $3; n->name = $6; n->def = (Node *) makeString($9); $$ = (Node *)n; } /* ALTER TABLE <relation> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */ | ALTER TABLE relation_expr DROP opt_column ColId opt_drop_behavior { AlterTableStmt *n = makeNode(AlterTableStmt); n->subtype = 'D'; n->relation = $3; n->name = $6; n->behavior = $7; $$ = (Node *)n; } /* ALTER TABLE <relation> ADD CONSTRAINT ... */ | ALTER TABLE relation_expr ADD TableConstraint { AlterTableStmt *n = makeNode(AlterTableStmt); n->subtype = 'C'; n->relation = $3; n->def = $5; $$ = (Node *)n; } /* ALTER TABLE <relation> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */ | ALTER TABLE relation_expr DROP CONSTRAINT name opt_drop_behavior { AlterTableStmt *n = makeNode(AlterTableStmt); n->subtype = 'X'; n->relation = $3; n->name = $6; n->behavior = $7; $$ = (Node *)n; } /* ALTER TABLE <relation> SET WITHOUT OIDS */ | ALTER TABLE relation_expr SET WITHOUT OIDS { AlterTableStmt *n = makeNode(AlterTableStmt); n->relation = $3; n->subtype = 'o'; $$ = (Node *)n; } /* ALTER TABLE <name> CREATE TOAST TABLE */ | ALTER TABLE qualified_name CREATE TOAST TABLE { AlterTableStmt *n = makeNode(AlterTableStmt); n->subtype = 'E'; $3->inhOpt = INH_NO; n->relation = $3; $$ = (Node *)n; } /* ALTER TABLE <name> OWNER TO UserId */ | ALTER TABLE qualified_name OWNER TO UserId { AlterTableStmt *n = makeNode(AlterTableStmt); n->subtype = 'U'; $3->inhOpt = INH_NO; n->relation = $3; n->name = $6; $$ = (Node *)n; } /* ALTER TABLE <name> CLUSTER ON <indexname> */ | ALTER TABLE qualified_name CLUSTER ON name { AlterTableStmt *n = makeNode(AlterTableStmt); n->subtype = 'L'; n->relation = $3; n->name = $6; $$ = (Node *)n; } ;alter_column_default: SET DEFAULT a_expr { /* Treat SET DEFAULT NULL the same as DROP DEFAULT */ if (exprIsNullConstant($3)) $$ = NULL; else $$ = $3; } | DROP DEFAULT { $$ = NULL; } ;opt_drop_behavior: CASCADE { $$ = DROP_CASCADE; } | RESTRICT { $$ = DROP_RESTRICT; } | /* EMPTY */ { $$ = DROP_RESTRICT; /* default */ } ;/***************************************************************************** * * QUERY : * close <portalname> * *****************************************************************************/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 = nconc(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)); } ;/* 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 { 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; $$ = (Node *)n; } | CREATE OptTemp TABLE qualified_name OF qualified_name '(' OptTableElementList ')' OptWithOids OnCommitOption { /* 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 = makeList1($6); n->constraints = NIL; n->hasoids = $10; n->oncommit = $11; $$ = (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 { $$ = makeList1($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; $$ = (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; $$ = (Node *)n; } | UNIQUE { Constraint *n = makeNode(Constraint); n->contype = CONSTR_UNIQUE; n->name = NULL; n->raw_expr = NULL; n->cooked_expr = NULL; n->keys = NULL; $$ = (Node *)n; } | PRIMARY KEY
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -