Re: Summing & Grouping in a Hierarchical Structure

From: Ben Morrow <ben(at)morrow(dot)me(dot)uk>
To: parrisdc(at)gmail(dot)com, pgsql-sql(at)postgresql(dot)org
Subject: Re: Summing & Grouping in a Hierarchical Structure
Date: 2013-02-23 20:13:30
Message-ID: 20130223201329.GA12863@anubis.morrow.me.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Quoth parrisdc(at)gmail(dot)com (Don Parris):
>
> Is it possible to use spaces in the ltree path, like so:
> TOP.Groceries.Food.Herbs & Spices
>
> Or do the elements of the path have to use underscores and dashes?

From the docs:

| A label is a sequence of alphanumeric characters and underscores (for
| example, in C locale the characters A-Za-z0-9_ are allowed). Labels
| must be less than 256 bytes long. [...]
|
| A label path is a sequence of zero or more labels separated by dots,
| for example L1.L2.L3, representing a path from the root of a
| hierarchical tree to a particular node. The length of a label path
| must be less than 65Kb, but keeping it under 2Kb is preferable.

If you need to store non-alphanumeric labels, one answer (as long as
they aren't too long) would be to use URL-encoding, like

TOP.Groceries.Food.Herbs_20_26_20Spices

Of course, you would need to encode _ as well, and you would need to be
sure the labels weren't going to come out too long. Another alternative
would be to MD5 each label and use (say) the first 10 bytes of that MD5
in hex as the ltree label. (Annoyingly there's only one
non-alphanumeric, so you can't use base64.) If you were going to do that
you would need to consider the possibility of an attacker arranging a
hash collision: I don't know where you're labels come from, so I don't
know if this would be an issue.

Ben

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Don Parris 2013-02-23 21:30:50 Re: Summing & Grouping in a Hierarchical Structure
Previous Message Misa Simic 2013-02-23 19:12:17 Re: Summing & Grouping in a Hierarchical Structure