Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit600c958

Browse files
committed
Add UNION, GROUP, DISTINCT to INSERT.
1 parentd70df16 commit600c958

File tree

4 files changed

+46
-10
lines changed

4 files changed

+46
-10
lines changed

‎src/backend/parser/analyze.c

Lines changed: 20 additions & 2 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.63 1998/01/10 04:29:47 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.64 1998/01/11 03:41:35 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -241,7 +241,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
241241
/* set up a range table */
242242
makeRangeTable(pstate,stmt->relname,stmt->fromClause);
243243

244-
qry->uniqueFlag=NULL;
244+
qry->uniqueFlag=stmt->unique;
245245

246246
/* fix the target list */
247247
icolumns=pstate->p_insert_columns=makeTargetNames(pstate,stmt->cols);
@@ -315,13 +315,31 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
315315
/* fix where clause */
316316
qry->qual=transformWhereClause(pstate,stmt->whereClause);
317317

318+
/* check having clause */
319+
if (stmt->havingClause)
320+
elog(NOTICE,"HAVING not yet supported; ignore clause",NULL);
321+
318322
/* now the range table will not change */
319323
qry->rtable=pstate->p_rtable;
320324
qry->resultRelation=refnameRangeTablePosn(pstate->p_rtable,stmt->relname);
321325

326+
qry->groupClause=transformGroupClause(pstate,
327+
stmt->groupClause,
328+
qry->targetList);
329+
330+
/* fix order clause */
331+
qry->sortClause=transformSortClause(pstate,
332+
NIL,
333+
NIL,
334+
qry->targetList,
335+
qry->uniqueFlag);
336+
322337
if (pstate->p_numAgg>0)
323338
finalizeAggregates(pstate,qry);
324339

340+
qry->unionall=stmt->unionall;/* in child, so unionClause may be false */
341+
qry->unionClause=transformUnionClause(stmt->unionClause,qry->targetList);
342+
325343
return (Query*)qry;
326344
}
327345

‎src/backend/parser/gram.y

Lines changed: 17 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.88 1998/01/10 04:29:50 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.89 1998/01/11 03:41:38 momjian Exp $
1414
*
1515
* HISTORY
1616
* AUTHORDATEMAJOR EVENT
@@ -2146,16 +2146,27 @@ InsertStmt: INSERT INTO relation_name opt_column_list insert_rest
21462146
insert_rest: VALUES '(' res_target_list2 ')'
21472147
{
21482148
$$ = makeNode(InsertStmt);
2149+
$$->unique = NULL;
21492150
$$->targetList = $3;
21502151
$$->fromClause = NIL;
2151-
$$->whereClause = NULL;
2152+
$$->whereClause = NIL;
2153+
$$->groupClause = NIL;
2154+
$$->havingClause = NIL;
2155+
$$->unionClause = NIL;
21522156
}
2153-
| SELECT res_target_list2 from_clause where_clause
2157+
| SELECT opt_unique res_target_list2
2158+
from_clause where_clause
2159+
group_clause having_clause
2160+
union_clause
21542161
{
21552162
$$ = makeNode(InsertStmt);
2156-
$$->targetList = $2;
2157-
$$->fromClause = $3;
2158-
$$->whereClause = $4;
2163+
$$->unique = $2;
2164+
$$->targetList = $3;
2165+
$$->fromClause = $4;
2166+
$$->whereClause = $5;
2167+
$$->groupClause = $6;
2168+
$$->havingClause = $7;
2169+
$$->unionClause = $8;
21592170
}
21602171
;
21612172

‎src/include/nodes/parsenodes.h

Lines changed: 6 additions & 1 deletion
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.42 1998/01/10 04:30:11 momjian Exp $
9+
* $Id: parsenodes.h,v 1.43 1998/01/11 03:41:49 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -574,10 +574,15 @@ typedef struct InsertStmt
574574
{
575575
NodeTagtype;
576576
char*relname;/* relation to insert into */
577+
char*unique;/* NULL, '*', or unique attribute name */
577578
List*cols;/* names of the columns */
578579
List*targetList;/* the target list (of ResTarget) */
579580
List*fromClause;/* the from clause */
580581
Node*whereClause;/* qualifications */
582+
List*groupClause;/* group by clause */
583+
Node*havingClause;/* having conditional-expression */
584+
List*unionClause;/* union subselect parameters */
585+
boolunionall;/* union without unique sort */
581586
}InsertStmt;
582587

583588
/* ----------------------

‎src/man/insert.l

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" This is -*-nroff-*-
22
.\" XXX standard disclaimer belongs here....
3-
.\" $Header: /cvsroot/pgsql/src/man/Attic/insert.l,v 1.5 1997/09/27 03:14:19 momjian Exp $
3+
.\" $Header: /cvsroot/pgsql/src/man/Attic/insert.l,v 1.6 1998/01/11 03:41:57 momjian Exp $
44
.TH INSERT SQL 11/05/95 PostgreSQL PostgreSQL
55
.SH NAME
66
insert\(em insert tuples to a relation
@@ -11,6 +11,8 @@ insert \(em insert tuples to a relation
1111
{\fBvalues\fR (expression1 [,expression-i] ) |
1212
\fBselect\fR expression1 [,expression-i]
1313
[\fBfrom\fR from-list] [\fBwhere\fR qual]
14+
[\fBgroupby\fR attr_name1 {, attr_name-i....}]
15+
[\fBunion{all}select\fR ...]
1416
.fi
1517
.SH DESCRIPTION
1618
.BR Insert

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp