So I'm trying to run the following query against a clickhouse db using a go echo api.
SELECT (SELECT round(sum(amount),2)
FROM activity
WHERE created_at >= FROM_UNIXTIME(?) AND created_at <= FROM_UNIXTIME(?)
AND account_id = ? AND funnel_id=? AND event_id=2 ) AS value, (SELECT round(sum(amount),2)
FROM activity
WHERE created_at >= FROM_UNIXTIME(?) AND created_at <= FROM_UNIXTIME(?)
AND account_id = ? AND funnel_id=? AND event_id=2 ) AS old_value;
The statement runs fine in DataGrip which I was using to test but when running in live code I get the following error: PrepareContext error: cannot get table name from query
Code I'm using to call the query is:
func ExecuteQuery(query string, values []interface{}) *sql.Rows {
stmt, err := conn.Prepare(query)
if err != nil {
log.Println(err)
}
rows, err := stmt.Query(values...)
if err != nil {
log.Println(err)
}
stmt.Close()
return rows
}
No idea what the issue is.
Tried changing using FROM activity LIMIT 1;
at the end of the query, that didn't work - same error.
No other ideas