Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Usage of "EXECUTE IMMEDIATE" in a query. Is it supported? #370

Closed
FMauroy opened this issue Sep 13, 2021 · 2 comments
Closed

Usage of "EXECUTE IMMEDIATE" in a query. Is it supported? #370

FMauroy opened this issue Sep 13, 2021 · 2 comments

Comments

@FMauroy
Copy link

FMauroy commented Sep 13, 2021

Hi, we have a table consisting of a Timestamp and then many columns, each for a sensor, containing float values. We need to be able to select one of these sensors through a variable (this works fine) and then display a graph using the timestamps and the values from the selected column. To achieve that, I tried using "EXECUTE IMMEDIATE". It doesn't fail, but I do not get the data. Also, the schema object contains all columns from the source table, not the 2 I expected (timestamp and the values from the selected column). I also tried storing the result of the execute into a TEMP table, to no avail. Now I'm trying with a CTE, but in that case, it doesn't find the CTE's table name (fails with the typical "Invalid project ID..."). Are execute commands supported? If not, is anyone aware of an alternate way to do this?
Thanks a lot !

Example

WITH DataPoints (Time as TIMESTAMP, Metric as DECIMAL) as
EXECUTE IMMEDIATE "SELECT CAST(Start_Date AS TIMESTAMP) as time, CAST(J1_PV as DECIMAL) as metric FROM project.dataset.table WHERE $__timeFilter(CAST(Start_Date AS TIMESTAMP))";
SELECT * FROM DataPoints;

Results in:

"Invalid project ID 'DataPoints'. Project IDs must contain 6-63 lowercase letters, digits, or dashes. Some project IDs also include domain name separated by a colon. IDs must start with a letter and may not end with a dash."

Note: "J1_PV" is the name of one of the columns, it will be ultimately be replaced by a concatenation of the SELECT statement and the variable value. Kept outside this to simplify. Project/dataset/table were redacted.

Specifications

  • Version: 2.0.2
  • Platform: Ubuntu VM
  • Grafana Version: 8.1.3
@FMauroy
Copy link
Author

FMauroy commented Sep 15, 2021

Hi, I ended up creating a view that would UNPIVOT the needed columns, and do a simple select from that view in the Grafana plugin. So I'm saved. But I'd still like to know if dynamic queries are supported or not. Cheers!

@ofir5300
Copy link
Collaborator

Hi @FMauroy, I am pretty sure it does not supported.
Sorry if its a naive question but why not simply use a nested query (like you ended up doing I guess)?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants