Following regex (s*select([^()]*))
giving all subqueries but it ignores when subquery contains any sql functions like max(), count(), ….etc
regex works for below
SELECT student.name, teacher.name, sub.subject_name
FROM student student
JOIN teacher teacher on teacher.id=student.teacher_id
JOIN (select subject.name subject_name, subject.id id from subject) sub on sub.id=teacher.subject_id
where student.id=1
it finds subquery as select subject.name subject_name, subject.id id from subject
but not for
SELECT student.name, teacher.name, sub.subject_name
FROM student student
JOIN teacher teacher on teacher.id=student.teacher_id
JOIN (select group_concat(subject.name) subject_names from subject)
where student.id=1
it doesn’t find match as select group_concat(subject.name) subject_names from subject
how can I get match…?
2
Answers
You can try regex
/((?:[^()]|((?:[^()]|([^()]*))*))*)/mg;
Challenge accepted. See if this leads to a viable solution:
Then parse the EXPLAIN by using the /../ comments and balancing parens.
(I edited whitespace for effect.)