Sql 递归查询:";表不包括';“不存在”;内部功能,但外部功能
我试图在Ubuntu 18.04上的MariaDB 10.3.7上的函数中封装一个递归临时表查询。我试着把陈述分解成更基本的部分,但在我把它们放在一起之前,它们都是正确的 这是我想将语句转换为函数的一个示例:Sql 递归查询:";表不包括';“不存在”;内部功能,但外部功能,sql,mariadb,Sql,Mariadb,我试图在Ubuntu 18.04上的MariaDB 10.3.7上的函数中封装一个递归临时表查询。我试着把陈述分解成更基本的部分,但在我把它们放在一起之前,它们都是正确的 这是我想将语句转换为函数的一个示例: with recursive Descendants as ( select * from Characters where id = 91402 union select c.* from Characters as c, Descendants as d
with recursive Descendants as (
select * from Characters where id = 91402
union
select c.* from Characters as c, Descendants as d
where d.id = c.mother_id or d.id = c.real_father_id
) select count(distinct(id)) from Descendants
create function count_descendants(cid int unsigned) returns int unsigned return (
with recursive Descendants as (
select * from Characters where id = cid
union
select c.* from Characters as c, Descendants as d
where d.id = c.mother_id or d.id = c.real_father_id
) select count(distinct(id)) from Descendants
);
它打印出后代字符的数量,这就是我想要的
以下是我到目前为止将其转化为函数的尝试:
with recursive Descendants as (
select * from Characters where id = 91402
union
select c.* from Characters as c, Descendants as d
where d.id = c.mother_id or d.id = c.real_father_id
) select count(distinct(id)) from Descendants
create function count_descendants(cid int unsigned) returns int unsigned return (
with recursive Descendants as (
select * from Characters where id = cid
union
select c.* from Characters as c, Descendants as d
where d.id = c.mother_id or d.id = c.real_father_id
) select count(distinct(id)) from Descendants
);
Maria接受这一点,但如果我尝试使用它:
select count_descendants(91402);
它将打印此错误消息:
ERROR 1146 (42S02) at line 12: Table 'ck2.Characters' doesn't exist
“ck2”是正在使用的数据库的名称。如果有人想看到,我可以发布模式
编辑:我已经在MariaDB的bug跟踪器上以bug的形式提交了它:这是一个尝试用数据库和模式名称指定表。“ck2.dbo.Characters”我不知道这是什么,但在名称中包含“dbo”会产生语法错误。使用“ck2.Characters”的结果与不包含数据库名称的结果相同。然后尝试将表名“Characters”替换为“ck2.Characters”,这就是我尝试的,没有任何区别。我不认为这是个问题,因为我已经
使用了ck2代码>在脚本的开头,我正在运行这些。