⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gram.y

📁 关系型数据库 Postgresql 6.5.2
💻 Y
📖 第 1 页 / 共 5 页
字号:
%{ /* -*-text-*- *//*#define YYDEBUG 1*//*------------------------------------------------------------------------- * * gram.y *	  POSTGRES SQL YACC rules/actions * * Copyright (c) 1994, Regents of the University of California * * * IDENTIFICATION *	  $Header: /usr/local/cvsroot/pgsql/src/backend/parser/gram.y,v 2.88.2.2 1999/09/14 06:07:35 thomas Exp $ * * HISTORY *	  AUTHOR			DATE			MAJOR EVENT *	  Andrew Yu			Sept, 1994		POSTQUEL to SQL conversion *	  Andrew Yu			Oct, 1994		lispy code conversion * * NOTES *	  CAPITALS are used to represent terminal symbols. *	  non-capitals are used to represent non-terminals. *	  SQL92-specific syntax is separated from plain SQL/Postgres syntax *	  to help isolate the non-extensible portions of the parser. * *	  if you use list, make sure the datum is a node so that the printing *	  routines work * * WARNING *	  sometimes we assign constants to makeStrings. Make sure we don't free *	  those. * *------------------------------------------------------------------------- */#include <string.h>#include <ctype.h>#include "postgres.h"#include "access/htup.h"#include "nodes/parsenodes.h"#include "nodes/print.h"#include "parser/gramparse.h"#include "parser/parse_type.h"#include "utils/acl.h"#include "utils/palloc.h"#include "catalog/catname.h"#include "utils/elog.h"#include "access/xact.h"#include "storage/lmgr.h"#include "utils/numeric.h"#include "parser/analyze.h"#include "catalog/pg_type.h"#ifdef MULTIBYTE#include "mb/pg_wchar.h"#endifstatic char saved_relname[NAMEDATALEN];  /* need this for complex attributes */static bool QueryIsRule = FALSE;static List *saved_In_Expr = NIL;static Oid	*param_type_info;static int	pfunc_num_args;extern List *parsetree;/* * If you need access to certain yacc-generated variables and find that * they're static by default, uncomment the next line.  (this is not a * problem, yet.) *//*#define __YYSCLASS*/static char *xlateSqlFunc(char *);static char *xlateSqlType(char *);static Node *makeA_Expr(int oper, char *opname, Node *lexpr, Node *rexpr);static Node *makeRowExpr(char *opr, List *largs, List *rargs);static void mapTargetColumns(List *source, List *target);static List *makeConstantList( A_Const *node);static char *FlattenStringList(List *list);static char *fmtId(char *rawid);static Node *makeIndexable(char *opname, Node *lexpr, Node *rexpr);static void param_type_init(Oid *typev, int nargs);static Node *doNegate(Node *n);Oid	param_type(int t); /* used in parse_expr.c *//* old versions of flex define this as a macro */#if defined(yywrap)#undef yywrap#endif /* yywrap */%}%union{	double				dval;	int					ival;	char				chr;	char				*str;	bool				boolean;	bool*				pboolean;	/* for pg_shadow privileges */	List				*list;	Node				*node;	Value				*value;	Attr				*attr;	TypeName			*typnam;	DefElem				*defelt;	ParamString			*param;	SortGroupBy			*sortgroupby;	JoinExpr			*joinexpr;	IndexElem			*ielem;	RangeVar			*range;	RelExpr				*relexp;	A_Indices			*aind;	ResTarget			*target;	ParamNo				*paramno;	VersionStmt			*vstmt;	DefineStmt			*dstmt;	RuleStmt			*rstmt;	InsertStmt			*astmt;}%type <node>	stmt,		AddAttrStmt, ClosePortalStmt,		CopyStmt, CreateStmt, CreateAsStmt, CreateSeqStmt, DefineStmt, DestroyStmt,		ExtendStmt, FetchStmt,	GrantStmt, CreateTrigStmt, DropTrigStmt,		CreatePLangStmt, DropPLangStmt,		IndexStmt, ListenStmt, UnlistenStmt, LockStmt, OptimizableStmt,		ProcedureStmt, RemoveAggrStmt, RemoveOperStmt,		RemoveFuncStmt, RemoveStmt,		RenameStmt, RevokeStmt, RuleStmt, TransactionStmt, ViewStmt, LoadStmt,		CreatedbStmt, DestroydbStmt, VacuumStmt, CursorStmt, SubSelect,		UpdateStmt, InsertStmt, select_clause, SelectStmt, NotifyStmt, DeleteStmt, 		ClusterStmt, ExplainStmt, VariableSetStmt, VariableShowStmt, VariableResetStmt,		CreateUserStmt, AlterUserStmt, DropUserStmt, RuleActionStmt%type <str>		opt_database1, opt_database2, location, encoding%type <ival>	opt_lock, lock_type%type <boolean>	opt_lmode%type <pboolean> user_createdb_clause, user_createuser_clause%type <str>		user_passwd_clause%type <str>		user_valid_clause%type <list>	user_group_list, user_group_clause%type <boolean>	TriggerActionTime, TriggerForSpec, PLangTrusted%type <str>		TriggerEvents, TriggerFuncArg%type <str>		relation_name, copy_file_name, copy_delimiter, def_name,		database_name, access_method_clause, access_method, attr_name,		class, index_name, name, func_name, file_name, aggr_argtype%type <str>		opt_id, opt_portal_name,		all_Op, MathOp, opt_name, opt_unique,		OptUseOp, opt_class, SpecialRuleRelation%type <str>		opt_level%type <str>		privileges, operation_commalist, grantee%type <chr>		operation, TriggerOneEvent%type <list>	stmtblock, stmtmulti,		result, relation_name_list, OptTableElementList,		OptInherit, definition,		opt_with, func_args, func_args_list,		oper_argtypes, RuleActionList, RuleActionBlock, RuleActionMulti,		opt_column_list, columnList, opt_va_list, va_list,		sort_clause, sortby_list, index_params, index_list, name_list,		from_clause, from_expr, table_list, opt_array_bounds, nest_array_bounds,		expr_list, attrs, res_target_list, res_target_list2,		def_list, opt_indirection, group_clause, TriggerFuncArgs,		opt_select_limit%type <node>	func_return%type <boolean>	set_opt%type <boolean>	TriggerForOpt, TriggerForType, OptTemp, OptTempType, OptTempScope%type <list>	for_update_clause, update_list%type <boolean>	opt_union%type <boolean>	opt_table%type <boolean>	opt_trans%type <list>	join_clause_with_union, join_clause, join_list, join_qual, using_list%type <node>	join_expr, using_expr%type <str>		join_outer%type <ival>	join_type%type <node>	position_expr%type <list>	extract_list, position_list%type <list>	substr_list, substr_from, substr_for, trim_list%type <list>	opt_interval%type <boolean> opt_inh_star, opt_binary, opt_instead, opt_with_copy,				index_opt_unique, opt_verbose, opt_analyze%type <boolean> opt_cursor%type <ival>	copy_dirn, def_type, opt_direction, remove_type,				opt_column, event%type <ival>	fetch_how_many%type <node>	select_limit_value, select_offset_value%type <list>	OptSeqList%type <defelt>	OptSeqElem%type <dstmt>	def_rest%type <astmt>	insert_rest%type <node>	OptTableElement, ConstraintElem%type <node>	columnDef, alter_clause%type <defelt>	def_elem%type <node>	def_arg, columnElem, where_clause,				a_expr, a_expr_or_null, b_expr, AexprConst,				in_expr, in_expr_nodes, not_in_expr, not_in_expr_nodes,				having_clause%type <list>	row_descriptor, row_list, c_list, c_expr%type <node>	row_expr%type <str>		row_op%type <node>	case_expr, case_arg, when_clause, case_default%type <list>	when_clause_list%type <ival>	sub_type%type <list>	OptCreateAs, CreateAsList%type <node>	CreateAsElement%type <value>	NumericOnly, FloatOnly, IntegerOnly%type <attr>	event_object, attr%type <sortgroupby>		sortby%type <ielem>	index_elem, func_index%type <range>	table_expr%type <relexp>	relation_expr%type <target>	res_target_el, res_target_el2%type <paramno> ParamNo%type <typnam>	Typename, opt_type, Array, Generic, Character, Datetime, Numeric%type <str>		generic, numeric, character, datetime%type <str>		extract_arg%type <str>		opt_charset, opt_collate%type <str>		opt_float%type <ival>	opt_numeric, opt_decimal%type <boolean>	opt_varying, opt_timezone%type <ival>	Iconst%type <str>		Sconst%type <str>		UserId, var_value, zone_value%type <str>		ColId, ColLabel%type <str>		TypeId%type <node>	TableConstraint%type <list>	constraint_list, constraint_expr%type <list>	default_list, default_expr%type <list>	ColPrimaryKey, ColQualList, ColQualifier%type <node>	ColConstraint, ColConstraintElem%type <list>	key_actions, key_action%type <str>		key_match, key_reference/* * If you make any token changes, remember to: *		- use "yacc -d" and update parse.h *		- update the keyword table in parser/keywords.c *//* Reserved word tokens * SQL92 syntax has many type-specific constructs. * So, go ahead and make these types reserved words, *  and call-out the syntax explicitly. * This gets annoying when trying to also retain Postgres' nice *  type-extensible features, but we don't really have a choice. * - thomas 1997-10-11 *//* Keywords (in SQL92 reserved words) */%token	ABSOLUTE, ACTION, ADD, ALL, ALTER, AND, ANY, AS, ASC,		BEGIN_TRANS, BETWEEN, BOTH, BY,		CASCADE, CASE, CAST, CHAR, CHARACTER, CHECK, CLOSE,		COALESCE, COLLATE, COLUMN, COMMIT,		CONSTRAINT, CREATE, CROSS, CURRENT, CURRENT_DATE, CURRENT_TIME, 		CURRENT_TIMESTAMP, CURRENT_USER, CURSOR,		DAY_P, DECIMAL, DECLARE, DEFAULT, DELETE, DESC, DISTINCT, DOUBLE, DROP,		ELSE, END_TRANS, EXCEPT, EXECUTE, EXISTS, EXTRACT,		FALSE_P, FETCH, FLOAT, FOR, FOREIGN, FROM, FULL,		GLOBAL, GRANT, GROUP, HAVING, HOUR_P,		IN, INNER_P, INSENSITIVE, INSERT, INTERSECT, INTERVAL, INTO, IS,		ISOLATION, JOIN, KEY, LANGUAGE, LEADING, LEFT, LEVEL, LIKE, LOCAL,		MATCH, MINUTE_P, MONTH_P, NAMES,		NATIONAL, NATURAL, NCHAR, NEXT, NO, NOT, NULLIF, NULL_P, NUMERIC,		OF, ON, ONLY, OPTION, OR, ORDER, OUTER_P,		PARTIAL, POSITION, PRECISION, PRIMARY, PRIOR, PRIVILEGES, PROCEDURE, PUBLIC,		READ, REFERENCES, RELATIVE, REVOKE, RIGHT, ROLLBACK,		SCROLL, SECOND_P, SELECT, SET, SUBSTRING,		TABLE, TEMP, TEMPORARY, THEN, TIME, TIMESTAMP, TIMEZONE_HOUR,		TIMEZONE_MINUTE, TO, TRAILING, TRANSACTION, TRIM, TRUE_P,		UNION, UNIQUE, UPDATE, USER, USING,		VALUES, VARCHAR, VARYING, VIEW,		WHEN, WHERE, WITH, WORK, YEAR_P, ZONE/* Keywords (in SQL3 reserved words) */%token	TRIGGER/* Keywords (in SQL92 non-reserved words) */%token	COMMITTED, SERIALIZABLE, TYPE_P/* Keywords for Postgres support (not in SQL92 reserved words) * * The CREATEDB and CREATEUSER tokens should go away * when some sort of pg_privileges relation is introduced. * - Todd A. Brandys 1998-01-01? */%token	ABORT_TRANS, ACCESS, AFTER, AGGREGATE, ANALYZE,		BACKWARD, BEFORE, BINARY, 		CACHE, CLUSTER, COPY, CREATEDB, CREATEUSER, CYCLE,		DATABASE, DELIMITERS, DO,		EACH, ENCODING, EXCLUSIVE, EXPLAIN, EXTEND,		FORWARD, FUNCTION, HANDLER,		INCREMENT, INDEX, INHERITS, INSTEAD, ISNULL,		LANCOMPILER, LIMIT, LISTEN, LOAD, LOCATION, LOCK_P,		MAXVALUE, MINVALUE, MODE, MOVE,		NEW, NOCREATEDB, NOCREATEUSER, NONE, NOTHING, NOTIFY, NOTNULL,		OFFSET, OIDS, OPERATOR, PASSWORD, PROCEDURAL,		RENAME, RESET, RETURNS, ROW, RULE,		SEQUENCE, SERIAL, SETOF, SHARE, SHOW, START, STATEMENT, STDIN, STDOUT,		TRUSTED, 		UNLISTEN, UNTIL, VACUUM, VALID, VERBOSE, VERSION/* Special keywords, not in the query language - see the "lex" file */%token <str>	IDENT, SCONST, Op%token <ival>	ICONST, PARAM%token <dval>	FCONST/* these are not real. they are here so that they get generated as #define's*/%token			OP/* precedence */%left		OR%left		AND%right		NOT%right		'='%nonassoc	'<' '>'%nonassoc	LIKE%nonassoc	BETWEEN%nonassoc	IN%left		Op				/* multi-character ops and user-defined operators */%nonassoc	NOTNULL%nonassoc	ISNULL%nonassoc	NULL_P%nonassoc	IS%left		'+' '-'%left		'*' '/' '%'%left		'^'%left		'|'				/* this is the relation union op, not logical or *//* Unary Operators */%right		':'%left		';'				/* end of statement or natural log */%right		UMINUS%left		'.'%left		'[' ']'%nonassoc	TYPECAST%left		UNION INTERSECT EXCEPT%%stmtblock:  stmtmulti opt_semi				{ parsetree = $1; }		;stmtmulti:  stmtmulti ';' stmt				{ $$ = lappend($1, $3); }		| stmt				{ $$ = lcons($1,NIL); }		;opt_semi:	';'		|	/*EMPTY*/		;		stmt :	  AddAttrStmt		| AlterUserStmt		| ClosePortalStmt		| CopyStmt		| CreateStmt		| CreateAsStmt		| CreateSeqStmt		| CreatePLangStmt		| CreateTrigStmt		| CreateUserStmt		| ClusterStmt		| DefineStmt		| DestroyStmt		| DropPLangStmt		| DropTrigStmt		| DropUserStmt		| ExtendStmt		| ExplainStmt		| FetchStmt		| GrantStmt		| IndexStmt		| ListenStmt		| UnlistenStmt		| LockStmt		| ProcedureStmt		| RemoveAggrStmt		| RemoveOperStmt		| RemoveFuncStmt		| RemoveStmt		| RenameStmt		| RevokeStmt		| OptimizableStmt		| RuleStmt		| TransactionStmt		| ViewStmt		| LoadStmt		| CreatedbStmt		| DestroydbStmt		| VacuumStmt		| VariableSetStmt		| VariableShowStmt		| VariableResetStmt		;/***************************************************************************** * * Create a new Postgres DBMS user * * *****************************************************************************/CreateUserStmt:  CREATE USER UserId user_passwd_clause user_createdb_clause			user_createuser_clause user_group_clause user_valid_clause				{					CreateUserStmt *n = makeNode(CreateUserStmt);					n->user = $3;					n->password = $4;					n->createdb = $5;					n->createuser = $6;					n->groupElts = $7;					n->validUntil = $8;					$$ = (Node *)n;				}		;/***************************************************************************** * * Alter a postresql DBMS user * * *****************************************************************************/AlterUserStmt:  ALTER USER UserId user_passwd_clause user_createdb_clause			user_createuser_clause user_group_clause user_valid_clause				{					AlterUserStmt *n = makeNode(AlterUserStmt);					n->user = $3;					n->password = $4;					n->createdb = $5;					n->createuser = $6;					n->groupElts = $7;					n->validUntil = $8;					$$ = (Node *)n;				}		;/***************************************************************************** * * Drop a postresql DBMS user * * *****************************************************************************/DropUserStmt:  DROP USER UserId				{					DropUserStmt *n = makeNode(DropUserStmt);					n->user = $3;					$$ = (Node *)n;				}		;user_passwd_clause:  WITH PASSWORD UserId		{ $$ = $3; }			| /*EMPTY*/							{ $$ = NULL; }		;user_createdb_clause:  CREATEDB				{					bool*  b;					$$ = (b = (bool*)palloc(sizeof(bool)));					*b = true;				}			| NOCREATEDB				{					bool*  b;					$$ = (b = (bool*)palloc(sizeof(bool)));					*b = false;				}			| /*EMPTY*/							{ $$ = NULL; }		;user_createuser_clause:  CREATEUSER				{					bool*  b;					$$ = (b = (bool*)palloc(sizeof(bool)));					*b = true;				}			| NOCREATEUSER				{					bool*  b;					$$ = (b = (bool*)palloc(sizeof(bool)));					*b = false;				}			| /*EMPTY*/							{ $$ = NULL; }		;user_group_list:  user_group_list ',' UserId				{					$$ = lcons((void*)makeString($3), $1);				}			| UserId				{					$$ = lcons((void*)makeString($1), NIL);				}		;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -