i have this SQL:
SELECT count(*) as ct
FROM classifications cls
WHERE
cls.classification_id = :classification_id
START WITH cls.classification_id = :root_classification_id
CONNECT BY NOCYCLE PRIOR cls.classification_id = cls.parent_id
and need to migrate it to postgresql 10.
I have already installed the extension tablefunc and tried with connectedby. here my try:
SELECT count(*) as ct
FROM classifications cls
WHERE
cls.classification_id = :classification_id
union
SELECT count(classification_id) FROM connectby('classifications','classification_id','parent_id',:root_classification_id,5)
as t(classification_id varchar, parent_id varchar,level int)
Problem is that the union is the wrong way because then you get 2 results of the count.