Hi Katefray
Thank you for the reply and documentation links. I have already tried with billing usage system table (system.billing.usage) and pricing system table (system.billing.list_prices) but unfortunately billing usage table doesn't have direct reference to system.query.history. So we can't join them and get the DBU usage and calculate the query cost.
Here is sample query. (It is not giving expected result)
SELECT q.workspace_id,
q.compute.warehouse_id,
q.compute.type,
q.read_files,
q.read_rows,
q.statement_text,
q.statement_type,
q.total_task_duration_ms,
b.usage_date,
b.usage_unit,
b.usage_quantity,
b.sku_name,
(b.usage_quantity * l.pricing.default) AS total_cost,
q.executed_by
FROM system.query.history q
JOIN system.billing.usage b
ON q.compute.warehouse_id = b.usage_metadata.warehouse_id
AND q.workspace_id = b.workspace_id
JOIN system.billing.list_prices l
ON l.sku_name = b.sku_name
WHERE q.workspace_id = "xxxxxxxxxxxx "
AND b.usage_date >= (current_date() - INTERVAL '1' DAY)
AND l.price_end_time IS NULL
Here is an example
1. Statement Type is SHOW. It took 0 milli seconds. the usage is showing 1.09 DBU, cost per DBU is 0.95 and total cost is 1.03 It doesn't make sense show sql statement is costing $1.03.
Thanks