From 3eb1c8227751aecede58e742a13b07127a7e2652 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 7 Oct 1999 04:23:24 +0000 Subject: Fix planner and rewriter to follow SQL semantics for tables that are mentioned in FROM but not elsewhere in the query: such tables should be joined over anyway. Aside from being more standards-compliant, this allows removal of some very ugly hacks for COUNT(*) processing. Also, allow HAVING clause without aggregate functions, since SQL does. Clean up CREATE RULE statement-list syntax the same way Bruce just fixed the main stmtmulti production. CAUTION: addition of a field to RangeTblEntry nodes breaks stored rules; you will have to initdb if you have any rules. --- src/backend/parser/analyze.c | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) (limited to 'src/backend/parser/analyze.c') diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 4bcf79a7277..08c209b2a5d 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -5,7 +5,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: analyze.c,v 1.120 1999/10/03 23:55:30 tgl Exp $ + * $Id: analyze.c,v 1.121 1999/10/07 04:23:11 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -298,18 +298,9 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt) qry->hasSubLinks = pstate->p_hasSubLinks; qry->hasAggs = pstate->p_hasAggs; - if (pstate->p_hasAggs || qry->groupClause) + if (pstate->p_hasAggs || qry->groupClause || qry->havingQual) parseCheckAggregates(pstate, qry); - /* - * If there is a havingQual but there are no aggregates, then there is - * something wrong with the query because HAVING must contain - * aggregates in its expressions! Otherwise the query could have been - * formulated using the WHERE clause. - */ - if (qry->havingQual && ! qry->hasAggs) - elog(ERROR, "SELECT/HAVING requires aggregates to be valid"); - /* * The INSERT INTO ... SELECT ... could have a UNION in child, so * unionClause may be false @@ -961,9 +952,9 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt) nothing_qry->commandType = CMD_NOTHING; addRangeTableEntry(pstate, stmt->object->relname, "*CURRENT*", - FALSE, FALSE); + FALSE, FALSE, FALSE); addRangeTableEntry(pstate, stmt->object->relname, "*NEW*", - FALSE, FALSE); + FALSE, FALSE, FALSE); nothing_qry->rtable = pstate->p_rtable; @@ -983,9 +974,9 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt) * equal to 2. */ addRangeTableEntry(pstate, stmt->object->relname, "*CURRENT*", - FALSE, FALSE); + FALSE, FALSE, FALSE); addRangeTableEntry(pstate, stmt->object->relname, "*NEW*", - FALSE, FALSE); + FALSE, FALSE, FALSE); pstate->p_last_resno = 1; pstate->p_is_rule = true; /* for expand all */ @@ -1048,18 +1039,9 @@ transformSelectStmt(ParseState *pstate, SelectStmt *stmt) qry->hasSubLinks = pstate->p_hasSubLinks; qry->hasAggs = pstate->p_hasAggs; - if (pstate->p_hasAggs || qry->groupClause) + if (pstate->p_hasAggs || qry->groupClause || qry->havingQual) parseCheckAggregates(pstate, qry); - /* - * If there is a havingQual but there are no aggregates, then there is - * something wrong with the query because HAVING must contain - * aggregates in its expressions! Otherwise the query could have been - * formulated using the WHERE clause. - */ - if (qry->havingQual && ! qry->hasAggs) - elog(ERROR, "SELECT/HAVING requires aggregates to be valid"); - /* * The INSERT INTO ... SELECT ... could have a UNION in child, so * unionClause may be false -- cgit v1.2.3