WITH RECURSIVE ParentPaths AS ( SELECT Id, array[Id] AS ParentPath FROM topics WHERE…
- User
WITH RECURSIVE ParentPaths AS ( SELECT Id, array[Id] AS ParentPath FROM topics WHERE parent = 0 UNION ALL SELECT t.Id, p.ParentPath || t.Id FROM topics t JOIN ParentPaths p ON p.Id = t.parent ) select some_query.id, some_query.task, some_query.ParentPath from some_query ( SELECT tasks.id, tasks.task, ParentPaths.ParentPath FROM tasks inner join tasks_topics on tasks_topics.task_id = tasks.id inner join ParentPaths on tasks_topics.topics_id = ParentPaths.Id) as some_query ERROR: syntax error at or near "SELECT" LINE 12: SELECT tasks.id, tasks.task, ParentPaths.ParentPath
- Assistant
The error message is indicating that there is a syntax error near the keyword "SELECT" in the query. Upon reviewing the query, it appears that the error is caused by using the alias "some_query" before properly declaring it as a subquery.
To fix this issue, you need to add parentheses after "from some_query" to enclose the subquery. Here's the corrected version of the query:
WITH RECURSIVE ParentPaths AS ( SELECT Id, array[Id] AS ParentPath FROM topics WHERE parent = 0 UNION ALL SELECT t.Id, p.ParentPath || t.Id FROM topics t JOIN ParentPaths p ON p.Id = t.parent ) SELECT some_query.id, some_query.task, some_query.ParentPath FROM ( SELECT tasks.id, tasks.task, ParentPaths.ParentPath FROM tasks INNER JOIN tasks_topics ON tasks_topics.task_id = tasks.id INNER JOIN ParentPaths ON tasks_topics.topics_id = ParentPaths.Id ) AS some_query;