Data typesversion 1.3
ltree
Tree paths such as categories and org charts.
What it is for
ltree stores a position in a tree as a dotted path (shop.clothing.shirts) and indexes it, so "everything under this node" and "all ancestors of this node" are single indexed queries instead of recursive CTEs.
Enable it
create extension if not exists ltree with schema extensions;Example
create table categories (id serial primary key, path ltree not null);
create index on categories using gist (path);
insert into categories (path) values ('shop'), ('shop.clothing'), ('shop.clothing.shirts');
-- the subtree under shop.clothing
select path from categories where path <@ 'shop.clothing';Questions
How do I enable ltree?
Run create extension if not exists ltree with schema extensions; in the SQL editor, or switch it on from the Extensions page in the console. You do not need superuser access.
Which version of ltree is installed?
1.3, on Postgres 17.6, as read from the running engine on 2026-10-08. Check yours with: select extversion from pg_extension where extname = 'ltree';
Upstream project: www.postgresql.org/docs/17/ltree.html