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
[FEATURE] SQL functions in WHERE clause not evaluated for required parameters (start_time), and projected parameter/response columns return null #686
Two related issues observed querying openai_admin.usage.completions.
1. Function expressions in the WHERE clause are not evaluated for required parameters
When a required parameter is supplied via a function expression rather than a literal, the value is not resolved and the parameter is dropped from the request, producing a 400 from the provider.
SELECT
json_extract(r.value, '$.project_id') AS project_id,
json_extract(r.value, '$.model') AS model,
date(u.start_time, 'unixepoch') AS usage_date,
json_extract(r.value, '$.input_tokens') AS input_tokens,
json_extract(r.value, '$.output_tokens') AS output_tokens
FROMopenai_admin.usage.completions u, json_each(u.results) r
WHEREu.start_time= strftime('%s', date('now', '-30 days'))
ANDu.bucket_width='1d'ANDu.group_by='project_id'ORDER BY usage_date, project_id;
The same query with the literal substituted does dispatch the request:
WHEREu.start_time=1781481600
Expected: scalar function expressions on the right hand side of a required parameter predicate are evaluated before request construction, and the resolved value is bound to the parameter.
2. Projected columns return null / zero when the request does succeed
With the literal form, the request succeeds but the projection is largely empty:
project_id resolves via json_extract(r.value, '$.project_id'), so json_each(u.results) is expanding correctly.
input_tokens and output_tokens are null despite being siblings of project_id in the same result object.
usage_date is 0, indicating u.start_time is not projectable in the response row even though it was supplied as a parameter. Parameter values should be echoed into the row so they can be projected and joined against.
model may legitimately be null given group_by = 'project_id', but should be confirmed.
Environment
Provider: openai_admin
Resource: openai_admin.usage.completions
stackql version:
Provider version:
Suspected areas
Parameter binding path: literal-only extraction from the WHERE clause, function expressions ignored rather than evaluated or rejected.
Response projection: parameter columns not merged into the emitted row; possible schema mismatch on the nested results[].result[] shape for the usage endpoints.
Acceptance criteria
WHERE start_time = strftime('%s', date('now', '-30 days')) dispatches a request with the resolved epoch value.
If an expression cannot be evaluated at plan time, stackql returns a clear error rather than silently dropping the parameter.
Projecting u.start_time returns the supplied parameter value.
input_tokens and output_tokens return values from the response payload.
Activity
feat: constant-fold WHERE function expressions for provider parameters (
feat: mcp credential (re)sourcing via server.env_file + reload_creden…