PostgreSQL 的 语法分析的理解(二)
2012-09-05 12:43
381 查看
对于PostgreSQL的语法分析,修改其 gram.y后,
-->
-->
在psql执行查询:select distinct id from a6;
在后台会显示:
In opt_distinct
In simple select
opt_distinct: DISTINCT { $$ = list_make1(NIL); } | DISTINCT ON '(' expr_list ')' { $$ = $4; } | ALL { $$ = NIL; } | /*EMPTY*/ { $$ = NIL; }
simple_select: SELECT opt_distinct target_list into_clause from_clause where_clause group_clause having_clause window_clause { SelectStmt *n = makeNode(SelectStmt); n->distinctClause = $2; n->targetList = $3; n->intoClause = $4; n->fromClause = $5; n->whereClause = $6; n->groupClause = $7; n->havingClause = $8; n->windowClause = $9; $$ = (Node *)n; } | values_clause { $$ = $1; } | TABLE relation_expr { /* same as SELECT * FROM relation_expr */ ColumnRef *cr = makeNode(ColumnRef); ResTarget *rt = makeNode(ResTarget); SelectStmt *n = makeNode(SelectStmt); cr->fields = list_make1(makeNode(A_Star)); cr->location = -1; rt->name = NULL; rt->indirection = NIL; rt->val = (Node *)cr; rt->location = -1; n->targetList = list_make1(rt); n->fromClause = list_make1($2); $$ = (Node *)n; } | select_clause UNION opt_all select_clause { $$ = makeSetOp(SETOP_UNION, $3, $1, $4); } | select_clause INTERSECT opt_all select_clause { $$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4); } | select_clause EXCEPT opt_all select_clause { $$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4); } ;
-->
opt_distinct: DISTINCT { $$ = list_make1(NIL); fprintf(stderr,"In opt_distinct\n"); } | DISTINCT ON '(' expr_list ')' { $$ = $4; } | ALL { $$ = NIL; } | /*EMPTY*/ { $$ = NIL; }
-->
simple_select: SELECT opt_distinct target_list into_clause from_clause where_clause group_clause having_clause window_clause { SelectStmt *n = makeNode(SelectStmt); n->distinctClause = $2; n->targetList = $3; n->intoClause = $4; n->fromClause = $5; n->whereClause = $6; n->groupClause = $7; n->havingClause = $8; n->windowClause = $9; $$ = (Node *)n; fprintf(stderr,"In simple select\n“); } | values_clause { $$ = $1; } | TABLE relation_expr { /* same as SELECT * FROM relation_expr */ ColumnRef *cr = makeNode(ColumnRef); ResTarget *rt = makeNode(ResTarget); SelectStmt *n = makeNode(SelectStmt); cr->fields = list_make1(makeNode(A_Star)); cr->location = -1; rt->name = NULL; rt->indirection = NIL; rt->val = (Node *)cr; rt->location = -1; n->targetList = list_make1(rt); n->fromClause = list_make1($2); $$ = (Node *)n; } | select_clause UNION opt_all select_clause { $$ = makeSetOp(SETOP_UNION, $3, $1, $4); } | select_clause INTERSECT opt_all select_clause { $$ = makeSetOp(SETOP_INTERSECT, $3, $1, $4); } | select_clause EXCEPT opt_all select_clause { $$ = makeSetOp(SETOP_EXCEPT, $3, $1, $4); } ;
在psql执行查询:select distinct id from a6;
在后台会显示:
In opt_distinct
In simple select
相关文章推荐
- PostgreSQL 的 语法分析的理解(四)
- PostgreSQL 的 语法分析的理解(五)
- PostgreSQL 的 语法分析的理解(七)
- 对PostgreSQL语法分析中 targetlist 的理解
- PostgreSQL 的 语法分析的理解(六)
- PostgreSQL 的 语法分析的理解(三)
- java语法,是理解、分析和解决任何java程序、框架、工程的万能切入点
- [李景山php] 深入理解PHP内核[读书笔记]--第二章:用户代码执行--PHP脚本的执行 词法分析和语法分析
- PostgreSQL的语法分析的学习研究(一)
- PostgreSQL 语法分析中所使用的List
- PostgreSQL 的 语法分析调用关系
- 程序理解和时间分析
- Makefile 语法分析
- Lua5.0 语法分析
- 理解Python中的with…as…语法
- LR语法分析-简单的LR技术
- 对Python中文分词模块结巴分词算法过程的理解和分析
- oo分析的过程是理解需求
- 自顶向下的语法分析–递归下降分析–表达式求值
- Android源码分析之理解Binder通信机制