Bug #12027
Embedded SQL SELECT INTO: aggregate column alias defect and BETWEEN support
Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
Due date:
% Done:
0%
billable:
No
vendor_id:
GCD
case_num:
version_reported:
version_resolved:
reviewer:
production:
No
env_name:
topics:
History
#1 Updated by Greg Shah 15 days ago
Embedded SQL SELECT INTO: aggregate column alias defect and BETWEEN support¶
Project: Database
Problem¶
FWD converts the simpler forms of the embedded SQL SELECT ... INTO statement: a single aggregate (COUNT(*), MAX, MIN, SUM, AVG) over one table, with a WHERE clause built from comparisons combined with AND / OR. The detection is in rules/annotations/database_general.rules (around lines 590-610) and the runtime goes through RecordBuffer.aggregate(...).
Two problems were found while testing this support (see #11892-10):
- A runtime defect in the simplest form. The FQL to SQL conversion emits a stray alias for the aggregate column. For example,
select count(*) from Item__Impl__becomesselect count(*) as from item, which the database rejects. So even the form the conversion supports does not work today. It is not yet known whetherMAXand the other aggregates are affected the same way asCOUNT. BETWEENis not converted in the WHERE clause of an embedded SQL statement.expressions.rulesmarks itsql.put(kw_between, cvt_lvl_none). A typical use is:
SELECT MAX(modtim) INTO iTime FROM payment WHERE payment.moddat BETWEEN dFrom AND dTo.
Work¶
- Fix the aggregate alias in the FQL to SQL conversion (
Fql2SqlConverteror wherever the select list for an aggregate is rendered), so that the generated SQL is valid on every supported dialect: PostgreSQL, SQL Server, MariaDB and H2. - Check every aggregate function, not only
COUNT(*):COUNT(field),MAX,MIN,SUMandAVG. - Add
BETWEEN(andNOT BETWEEN) to the embedded SQL WHERE clause conversion, with the 4GL semantics for the unknown value at either bound. - Check that a qualified column reference written with whitespace before the dot (
table .field), which the 4GL accepts, converts correctly. - Update the gap marking for
count()andSELECTonce the work is done. The other unsupported constructs (DISTINCT,GROUP BY,HAVING, joins,IN,LIKE, arithmetic on an aggregate, several aggregates in one statement) stay out of scope for this task unless they turn out to be trivial.
Testcases¶
Each testcase needs an OpenEdge baseline.
SELECT COUNT(*) INTOover an empty table, a table with rows, and with a WHERE clause that matches none, one and many rows.- The same for
MAX,MIN,SUMandAVGon integer, decimal, date and character fields, including the result when no row matches. - WHERE clauses using
=,<>,<,>,AND,ORand parentheses, comparing with variables, literals and''. BETWEENandNOT BETWEENwith dates, integers and character values, and with an unknown value at each bound.- All of the above on PostgreSQL, SQL Server and H2 at least.