Re: Summing & Grouping in a Hierarchical Structure - Mailing list pgsql-sql

From Ben Morrow
Subject Re: Summing & Grouping in a Hierarchical Structure
Date
Msg-id 20130223201329.GA12863@anubis.morrow.me.uk
Whole thread Raw
In response to Re: Summing & Grouping in a Hierarchical Structure  (Don Parris <parrisdc@gmail.com>)
Responses Re: Summing & Grouping in a Hierarchical Structure
List pgsql-sql
Quoth parrisdc@gmail.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




pgsql-sql by date:

Previous
From: Misa Simic
Date:
Subject: Re: Summing & Grouping in a Hierarchical Structure
Next
From: Don Parris
Date:
Subject: Re: Summing & Grouping in a Hierarchical Structure