【发布时间】:2021-10-30 11:41:40
【问题描述】:
我正在尝试在格拉纳达查询中实现 MySQL 过程(使用 if/else 语句)。唯一的问题是它不会让我创建我的过程并从同一个查询中调用它......
错误
db query error: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CALL tester(true)' at line 44
我确信问题不在于我的语法,但查询的外观如下:
CREATE PROCEDURE tester(
IN is_empty BOOLEAN
)
BEGIN
IF(is_empty) THEN
SELECT
...
from $dbName.table1
where KernelName IN ($KernelNameFilter) AND `gpu-id` in ($gpuFilter) AND `Index` in ($DispatchIDFilter)
union SELECT
...
from $dbName.table1
where KernelName IN ($KernelNameFilter) AND `gpu-id` in ($gpuFilter) AND `Index` in ($DispatchIDFilter)
ELSE
SELECT
...
from $dbName.table1
where KernelName IN ($KernelNameFilter) AND `gpu-id` in ($gpuFilter) AND `Index` in ($DispatchIDFilter);
END IF;
END;
CALL tester(true);
它们似乎是独立工作的,但我不知道 Grafana 为什么不喜欢这种语法。有什么想法吗?
注意: 是的,我需要在 Grafana 查询 b/c 中创建过程我需要引用本地 Grafana 变量(即 $KernelNameFilter、$gpuFilter、...)
【问题讨论】:
-
我怀疑您看到的问题的原因是
mysqli和PDO不会自动支持多个查询。在任何情况下,每次要运行该过程时都创建该过程是多余的。您应该创建一次过程(如果需要,使用 MySQL Workbench 等外部工具)然后调用它。如果您需要局部变量,请将它们作为参数传入CALL。
标签: mysql stored-procedures grafana