Skip to content
Advertisement

Query to group by maximum depth of PostgreSQL Ltree?

I want to query for all products with the name “Shania Twain”, but I want group them only by the tree with the deepest nlevel.

Assuming I have a table like the following with the name categories

So, for example,

The problem lies with the HAVING clause requiring a boolean expression. The clause MAX(nlevel(cat.tree)) will return an integer.

How do I go about doing this?

Thanks in advance

Mahmoud

Advertisement

Answer

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement