Does PostgreSQL have a pseudo-column like "LEVEL" in Oracle? -
does postgresql have pseudo-column "level" in oracle?
if not, how can create column similar "level"?
well, first of all, postgres not have hierarchical queries. no connect by
, therefore no level
.
you can similar things recursive cte , level
column that's incremented every recursion.
query in oracle:
select employee_id, last_name, manager_id, level employees connect prior employee_id = manager_id;
.. translated recursive cte in postgres:
with recursive cte ( select employee_id, last_name, manager_id, 1 level employees union select e.employee_id, e.last_name, e.manager_id, c.level + 1 cte c join employees e on e.manager_id = c.employee_id ) select * cte;
Comments
Post a Comment