Skip to content

Commit e6c714b

Browse files
committed
Bye CursorStmt, now use SelectStmt.
1 parent e7b205b commit e6c714b

File tree

4 files changed

+26
-69
lines changed

4 files changed

+26
-69
lines changed

src/backend/parser/analyze.c

Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.62 1998/01/09 20:05:49 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.63 1998/01/10 04:29:47 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -39,7 +39,7 @@ static Query *transformExtendStmt(ParseState *pstate, ExtendStmt *stmt);
3939
static Query *transformRuleStmt(ParseState *query, RuleStmt *stmt);
4040
static Query *transformSelectStmt(ParseState *pstate, SelectStmt *stmt);
4141
static Query *transformUpdateStmt(ParseState *pstate, UpdateStmt *stmt);
42-
static Query *transformCursorStmt(ParseState *pstate, CursorStmt *stmt);
42+
static Query *transformCursorStmt(ParseState *pstate, SelectStmt *stmt);
4343
static Query *transformCreateStmt(ParseState *pstate, CreateStmt *stmt);
4444

4545
List *extras = NIL;
@@ -175,12 +175,11 @@ transformStmt(ParseState *pstate, Node *parseTree)
175175
result = transformUpdateStmt(pstate, (UpdateStmt *) parseTree);
176176
break;
177177

178-
case T_CursorStmt:
179-
result = transformCursorStmt(pstate, (CursorStmt *) parseTree);
180-
break;
181-
182178
case T_SelectStmt:
183-
result = transformSelectStmt(pstate, (SelectStmt *) parseTree);
179+
if (!((SelectStmt *)parseTree)->portalname)
180+
result = transformSelectStmt(pstate, (SelectStmt *) parseTree);
181+
else
182+
result = transformCursorStmt(pstate, (SelectStmt *) parseTree);
184183
break;
185184

186185
default:
@@ -873,6 +872,9 @@ transformUpdateStmt(ParseState *pstate, UpdateStmt *stmt)
873872
qry->rtable = pstate->p_rtable;
874873
qry->resultRelation = refnameRangeTablePosn(pstate->p_rtable, stmt->relname);
875874

875+
if (pstate->p_numAgg > 0)
876+
finalizeAggregates(pstate, qry);
877+
876878
/* make sure we don't have aggregates in the where clause */
877879
if (pstate->p_numAgg > 0)
878880
parseCheckAggregates(pstate, qry);
@@ -886,47 +888,15 @@ transformUpdateStmt(ParseState *pstate, UpdateStmt *stmt)
886888
*
887889
*/
888890
static Query *
889-
transformCursorStmt(ParseState *pstate, CursorStmt *stmt)
891+
transformCursorStmt(ParseState *pstate, SelectStmt *stmt)
890892
{
891-
Query *qry = makeNode(Query);
892-
893-
/*
894-
* in the old days, a cursor statement is a 'retrieve into portal'; If
895-
* you change the following, make sure you also go through the code in
896-
* various places that tests the kind of operation.
897-
*/
898-
qry->commandType = CMD_SELECT;
893+
Query *qry;
899894

900-
/* set up a range table */
901-
makeRangeTable(pstate, NULL, stmt->fromClause);
902-
903-
qry->uniqueFlag = stmt->unique;
895+
qry = transformSelectStmt(pstate, stmt);
904896

905897
qry->into = stmt->portalname;
906898
qry->isPortal = TRUE;
907899
qry->isBinary = stmt->binary; /* internal portal */
908900

909-
/* fix the target list */
910-
qry->targetList = transformTargetList(pstate, stmt->targetList);
911-
912-
/* fix where clause */
913-
qry->qual = transformWhereClause(pstate, stmt->whereClause);
914-
915-
/* fix order clause */
916-
qry->sortClause = transformSortClause(pstate,
917-
stmt->sortClause,
918-
NIL,
919-
qry->targetList,
920-
qry->uniqueFlag);
921-
/* fix group by clause */
922-
qry->groupClause = transformGroupClause(pstate,
923-
stmt->groupClause,
924-
qry->targetList);
925-
926-
qry->rtable = pstate->p_rtable;
927-
928-
if (pstate->p_numAgg > 0)
929-
finalizeAggregates(pstate, qry);
930-
931-
return (Query *) qry;
901+
return qry;
932902
}

src/backend/parser/gram.y

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.87 1998/01/09 21:26:12 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.88 1998/01/10 04:29:50 momjian Exp $
1414
*
1515
* HISTORY
1616
* AUTHOR DATE MAJOR EVENT
@@ -2226,12 +2226,13 @@ UpdateStmt: UPDATE relation_name
22262226
* CURSOR STATEMENTS
22272227
*
22282228
*****************************************************************************/
2229-
22302229
CursorStmt: DECLARE name opt_binary CURSOR FOR
2231-
SELECT opt_unique res_target_list2
2232-
from_clause where_clause group_clause sort_clause
2230+
SELECT opt_unique res_target_list2
2231+
from_clause where_clause
2232+
group_clause having_clause
2233+
union_clause sort_clause
22332234
{
2234-
CursorStmt *n = makeNode(CursorStmt);
2235+
SelectStmt *n = makeNode(SelectStmt);
22352236

22362237
/* from PORTAL name */
22372238
/*
@@ -2251,7 +2252,9 @@ CursorStmt: DECLARE name opt_binary CURSOR FOR
22512252
n->fromClause = $9;
22522253
n->whereClause = $10;
22532254
n->groupClause = $11;
2254-
n->sortClause = $12;
2255+
n->havingClause = $12;
2256+
n->unionClause = $13;
2257+
n->sortClause = $14;
22552258
$$ = (Node *)n;
22562259
}
22572260
;

src/include/nodes/nodes.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: nodes.h,v 1.21 1998/01/09 21:13:43 momjian Exp $
9+
* $Id: nodes.h,v 1.22 1998/01/10 04:30:08 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -145,7 +145,6 @@ typedef enum NodeTag
145145
T_InsertStmt,
146146
T_DeleteStmt,
147147
T_UpdateStmt,
148-
T_CursorStmt,
149148
T_SelectStmt,
150149
T_AddAttrStmt,
151150
T_AggregateStmt,

src/include/nodes/parsenodes.h

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: parsenodes.h,v 1.41 1998/01/09 20:06:08 momjian Exp $
9+
* $Id: parsenodes.h,v 1.42 1998/01/10 04:30:11 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -604,23 +604,6 @@ typedef struct UpdateStmt
604604
List *fromClause; /* the from clause */
605605
} UpdateStmt;
606606

607-
/* ----------------------
608-
* Create Cursor Statement
609-
* ----------------------
610-
*/
611-
typedef struct CursorStmt
612-
{
613-
NodeTag type;
614-
char *portalname; /* the portal (cursor) to create */
615-
bool binary; /* a binary (internal) portal? */
616-
char *unique; /* NULL, "*", or unique attribute name */
617-
List *targetList; /* the target list (of ResTarget) */
618-
List *fromClause; /* the from clause */
619-
Node *whereClause; /* qualifications */
620-
List *groupClause; /* group by clause */
621-
List *sortClause; /* sort clause (a list of SortGroupBy's) */
622-
} CursorStmt;
623-
624607
/* ----------------------
625608
* Select Statement
626609
* ----------------------
@@ -637,6 +620,8 @@ typedef struct SelectStmt
637620
Node *havingClause; /* having conditional-expression */
638621
List *unionClause; /* union subselect parameters */
639622
List *sortClause; /* sort clause (a list of SortGroupBy's) */
623+
char *portalname; /* the portal (cursor) to create */
624+
bool binary; /* a binary (internal) portal? */
640625
bool unionall; /* union without unique sort */
641626
} SelectStmt;
642627

0 commit comments

Comments
 (0)