1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-18 17:42:25 +03:00

Add UNION, GROUP, DISTINCT to INSERT.

This commit is contained in:
Bruce Momjian
1998-01-11 03:41:57 +00:00
parent d70df16a76
commit 600c958a30
4 changed files with 46 additions and 10 deletions

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.63 1998/01/10 04:29:47 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.64 1998/01/11 03:41:35 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -241,7 +241,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
/* set up a range table */
makeRangeTable(pstate, stmt->relname, stmt->fromClause);
qry->uniqueFlag = NULL;
qry->uniqueFlag = stmt->unique;
/* fix the target list */
icolumns = pstate->p_insert_columns = makeTargetNames(pstate, stmt->cols);
@ -315,13 +315,31 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
/* fix where clause */
qry->qual = transformWhereClause(pstate, stmt->whereClause);
/* check having clause */
if (stmt->havingClause)
elog(NOTICE, "HAVING not yet supported; ignore clause", NULL);
/* now the range table will not change */
qry->rtable = pstate->p_rtable;
qry->resultRelation = refnameRangeTablePosn(pstate->p_rtable, stmt->relname);
qry->groupClause = transformGroupClause(pstate,
stmt->groupClause,
qry->targetList);
/* fix order clause */
qry->sortClause = transformSortClause(pstate,
NIL,
NIL,
qry->targetList,
qry->uniqueFlag);
if (pstate->p_numAgg > 0)
finalizeAggregates(pstate, qry);
qry->unionall = stmt->unionall; /* in child, so unionClause may be false */
qry->unionClause = transformUnionClause(stmt->unionClause, qry->targetList);
return (Query *) qry;
}

View File

@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.88 1998/01/10 04:29:50 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.89 1998/01/11 03:41:38 momjian Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@ -2146,16 +2146,27 @@ InsertStmt: INSERT INTO relation_name opt_column_list insert_rest
insert_rest: VALUES '(' res_target_list2 ')'
{
$$ = makeNode(InsertStmt);
$$->unique = NULL;
$$->targetList = $3;
$$->fromClause = NIL;
$$->whereClause = NULL;
$$->whereClause = NIL;
$$->groupClause = NIL;
$$->havingClause = NIL;
$$->unionClause = NIL;
}
| SELECT res_target_list2 from_clause where_clause
| SELECT opt_unique res_target_list2
from_clause where_clause
group_clause having_clause
union_clause
{
$$ = makeNode(InsertStmt);
$$->targetList = $2;
$$->fromClause = $3;
$$->whereClause = $4;
$$->unique = $2;
$$->targetList = $3;
$$->fromClause = $4;
$$->whereClause = $5;
$$->groupClause = $6;
$$->havingClause = $7;
$$->unionClause = $8;
}
;