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

From Don Parris
Subject Re: Summing & Grouping in a Hierarchical Structure
Date
Msg-id CAJ-7yomzgaohdJW5HhJ=c4FCQ389id4LWb-2Nye9dmwkT+Lk4A@mail.gmail.com
Whole thread Raw
In response to Re: Summing & Grouping in a Hierarchical Structure  (Ben Morrow <ben@morrow.me.uk>)
List pgsql-sql
Misa & Ben,

Thanks.  I guess I overlooked that in the docs.  I did see the part about the 65KB.  I don't see my labels getting overly long.  I'll be fine with Herbs_Spices.  I make up the labels myself, so it's really no big deal.

Alexander & Bryan - Many thanks for the help!



On Sat, Feb 23, 2013 at 3:13 PM, Ben Morrow <ben@morrow.me.uk> wrote:
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




--
D.C. Parris, FMP, Linux+, ESL Certificate
Minister, Security/FM Coordinator, Free Software Advocate
GPG Key ID: F5E179BE

pgsql-sql by date:

Previous
From: Ben Morrow
Date:
Subject: Re: Summing & Grouping in a Hierarchical Structure
Next
From: Don Parris
Date:
Subject: Using Ltree For Hierarchical Structures