You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
An aggregate inside CAST throws g is not defined: SELECT CAST(COUNT(*) AS INTEGER) #2764
An aggregate inside CAST or CONVERT throws g is not defined. It is the most common run-time error in the sqllogictest run (44 times in the first 76 files of test/random/), reproduced on develop (06211a0), compared with SQLite 3.43.2:
Query
AlaSQL
SQLite
SELECT CAST(COUNT(*) AS INTEGER) AS n
g is not defined
1
SELECT CAST(COUNT(*) AS INTEGER) AS n FROM t
g is not defined
2
SELECT CAST(SUM(x) AS FLOAT) AS n FROM t
g is not defined
3
SELECT CAST(COUNT(*) AS STRING) AS n FROM t
g is not defined
'2'
SELECT CONVERT(INT, COUNT(*)) AS n FROM t
g is not defined
SELECT ABS(COUNT(*)) AS n FROM t
2
2
SELECT COUNT(*) + 0 AS n
1
1
(t holds two rows, x = 1 and 2.) An aggregate inside other functions and operators works; only CAST and CONVERT around it fail. g is the name of the group row in the generated code, so the generated CAST code seems to be compiled where no group row exists. #2594 counts this error among the run-time errors.
The same family gives a wrong value instead of the error when an aggregate also sits outside the CAST (sqllogictest, about 900 failures; develop06211a0 and npm 4.20.1):
Query
AlaSQL
SQLite
SELECT COUNT(*) * CAST(COUNT(*) AS INTEGER)
0
1
SELECT COUNT(*) * COALESCE(CAST(COUNT(*) AS INTEGER), 5)
Activity
mathiasrw commentedon Oct 21, 2026
The same family gives a wrong value instead of the error when an aggregate also sits outside the
CAST(sqllogictest, about 900 failures;develop06211a0 and npm 4.20.1):SELECT COUNT(*) * CAST(COUNT(*) AS INTEGER)SELECT COUNT(*) * COALESCE(CAST(COUNT(*) AS INTEGER), 5)SELECT 2 * COALESCE(CAST(COUNT(*) AS INTEGER), 5)g is not definedStill not breaking: the value is wrong today.
mateuscmtropical commentedon Nov 11, 2026
Hi, I'd like to work on this one.
mateuscmtropical commentedon Nov 11, 2026
Hi, I've opened a PR for this: #3002
Find aggregates inside CAST and CONVERT to close AlaSQL#2764 (AlaSQL#…