0

I'm new to SQL. I'm using MySQL Ver 15.1 Distrib 10.3.27-MariaDB. For the following. I'm trying to compute paths in a graph like this: a->b.

create table edges
(
    start varchar(4),
    end   varchar(4)
);
insert edges(start, end) values ("a", "b");

with recursive cte (path, last) as
(
    select "a", "a"
    union all
    select CONCAT(path, "->", edges.end), edges.end from cte, edges
           where cte.last = edges.start
)
select * from cte;

I was expected to get two rows like this [("a", "a"), ("a->b", "b")] but instead got [("a", "a"), ("a", "b")]. Why was there no concatenation?

2
  • So you are actually using mariaDB and not MySQL. They started quite similiar but now are not at all similiar Commented Feb 14 at 8:32
  • Yeah ... I know. Commented Feb 14 at 8:39

1 Answer 1

0

datatype and length are derived from the first select you should be seeing an error

try

with recursive cte (path, last) as
(
    select cast("a" as char(100)), cast("a" as char(100))
    union all
    select CONCAT(path, "->", edges.end), edges.end from cte, edges
           where cte.last = edges.start
)
select * from cte;

https://dbfiddle.uk/WAz2Jjg0

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.