Use of PostgreSQL cursors in Grafana

Is it possible to use database cursors in grafana?. I mean the cursor that creates the database in order to loop over the rows of the result of a query, not to the cursor of Grafana. I am using Postgresql as database.
I have tested the following in the query of one of the panels:

BEGIN;
SELECT graf.conc_tanques_calibracion('mi_cursor', true, true,
	'2022-04-23 10:19:06', '2024-09-02 09:46:05');
FETCH ALL FROM mi_cursor;
COMMIT;

Where graf.conc_tanques_calibracion is the function that returns the cursor.
If I issue the same sql commands from the psql tool, I get the correct results, but when used in grafana as query source of one panel and pressing the “Run query” button, I get the following message: “convert frame from rows error: sql: expected 9 destination arguments in Scan, not 1”
The result of my query has 9 columns.

  1. Try to always avoid cursors, try to do it in one statement
  2. If you must use cursors make your query into a stored procedure and try to see if you can that stored procedure from grafana

Well, the reason why I am using (database) cursors is that I have to base the panel on a query that pivots some rows of a table. In order to do the pivoting in postgresql, I have to dinamically generate the sql code (see the link I have provided) and the number of resulting columns is not known in advance.
In order to do all this job, I have decided that it will be done by postgresql stored functions. A postgresql function that returns the result of a query consisnting in more than one row, has to have its returning type declared by specifying all the columns of the resulting query. As this is not known in a pivoted table, I have decided that the stored function will not return the result of a query, but a cursor. Then, the query in which the panel is based (the one stated in the first message of this post), will run the function returnning the cursor, and then fetch all the rows from the cursor. So, graf.conc_tanques_calibracion, is already a stored function, the one that returns the cursor.
But I get the mentioned error.

I have solved my problem by making the stored postgresql function to return, not a cursor, but a text string consisting in the sql code that returns the desired rows. This sql code text is appropiately made to do the pivoting.
So, I create a global variable (template variable) in grafana of type query, that by means of a sql sentence, executes the stored function, so that the result of this function, the sql sentence, becomes the value of the template variable.
Afterwards, I put this template variable in the sql query in which the panel is based.
And that’s all.
Anyway, this does not answer the original question: Is it possible to use database cursors in grafana?, so I still do not accept a solution.