From: | 高增琦 <pgf00a(at)gmail(dot)com> |
---|---|
To: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Do we support using agg or window functions in delete statement? |
Date: | 2017-01-11 07:46:48 |
Message-ID: | CAFmBtr1XmDki9caowb9GQHqxaxH4EgVf5YiTSqMj1kPA7Rn-2w@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi,
In transformDeleteStmt:
qry->hasWindowFuncs = pstate->p_hasWindowFuncs;
qry->hasAggs = pstate->p_hasAggs;
if (pstate->p_hasAggs)
parseCheckAggregates(pstate, qry);
These code set agg and window function status for delete query,
but there is no similar code in transformInsertStmt and
transformUpdateStmt.
Do we support using agg or window function in delete statement?
Or, this code should be removed?
Some history of these code:
1. 1996-7-9 "Postgres95 1.01 Distribution - Virgin Sources":
Introduce agg check for insert/update/delete.
in transformDeleteStmt:
/* make sure we don't have aggregates in the where clause */
if (pstate->p_numAgg > 0)
parseCheckAggregates(pstate, qry);
in transformInsertStmt:
if (pstate->p_numAgg > 0)
finalizeAggregates(pstate, qry);
in transformUpdateStmt:
/* make sure we don't have aggregates in the where clause */
if (pstate->p_numAgg > 0)
parseCheckAggregates(pstate, qry);
2. 2006-6-21 "Disallow aggregate functions in UPDATE commands (unless
within a sub-SELECT)":
Change parseCheckAggregates to ereport in transformUpdateStmt.
in transformUpdateStmt:
if (pstate->p_hasAggs)
ereport(ERROR,
(errcode(ERRCODE_GROUPING_ERROR),
errmsg("cannot use aggregate function in UPDATE")));
3. 2006-8-2 "Add support for multi-row VALUES clauses as part of INSERT
statements":
Change parseCheckAggregates in insert to ereport.
in transformInsertStmt:
if (pstate->p_hasAggs)
ereport(ERROR,
(errcode(ERRCODE_GROUPING_ERROR),
errmsg("cannot use aggregate function in VALUES")));
4. 2008-12-28 "Support window functions a la SQL:2008.":
Add window function related check for insert/update/delete.
(use the same style as agg)
in transformDeleteStmt:
qry->hasAggs = pstate->p_hasAggs;
if (pstate->p_hasAggs)
parseCheckAggregates(pstate, qry);
qry->hasWindowFuncs = pstate->p_hasWindowFuncs;
if (pstate->p_hasWindowFuncs)
parseCheckWindowFuncs(pstate, qry);
in transformInsertStmt:
if (pstate->p_hasAggs)
ereport(ERROR,
(errcode(ERRCODE_GROUPING_ERROR),
errmsg("cannot use aggregate function in VALUES"),
parser_errposition(pstate,
locate_agg_of_level((Node *) qry, 0))));
if (pstate->p_hasWindowFuncs)
ereport(ERROR,
(errcode(ERRCODE_WINDOWING_ERROR),
errmsg("cannot use window function in VALUES"),
parser_errposition(pstate,
locate_windowfunc((Node *) qry))));
in transformUpdateStmt:
if (pstate->p_hasAggs)
ereport(ERROR,
(errcode(ERRCODE_GROUPING_ERROR),
errmsg("cannot use aggregate function in UPDATE"),
parser_errposition(pstate,
locate_agg_of_level((Node *) qry, 0))));
if (pstate->p_hasWindowFuncs)
ereport(ERROR,
(errcode(ERRCODE_WINDOWING_ERROR),
errmsg("cannot use window function in UPDATE"),
parser_errposition(pstate,
locate_windowfunc((Node *) qry))));
5. 2012-8-10 "Centralize the logic for detecting misplaced aggregates,
window funcs, etc.":
Remove ereport in update/insert.
Thanks
--
GaoZengqi
pgf00a(at)gmail(dot)com
zengqigao(at)gmail(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Paquier | 2017-01-11 07:50:13 | Re: [PATCH] Refactor "if(strspn(str, ...) == strlen(str)" code |
Previous Message | Etsuro Fujita | 2017-01-11 07:45:12 | Re: postgres_fdw bug in 9.6 |