3

the doc of Postgres Ltree said that

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.

However, it does not said that if we set the locale to 'en_US.UTF-8', what is the valid character can be used in Postgres Ltree. So, can dash(hyphen) be used in the label of Ltree?

5
  • 1
    The fact that it mentions the locale means that it'll be in the current locale's encoding, so yes, if the database is UTF-8 you can use UTF-8 chars. Commented Apr 27, 2015 at 4:57
  • @CraigRinger, yes i have test that i can even insert a chinese char.
    – andy
    Commented Apr 27, 2015 at 6:24
  • @andy Any luck on using hypen (-) inside a ltree label?
    – Charizard_
    Commented Nov 27, 2015 at 4:37
  • 1
    @Charizard_ Sorry for not updating the answer. Yes, i have finally figured out that it is one of our DBA that changed the source of ltree and recompile it with supporting the dash(-) char. We have a single table with more than 6B records
    – andy
    Commented Dec 3, 2015 at 3:24
  • FYI Postgres 16 will include support for - via this patch which was merged recently.
    – Tim Bunce
    Commented Mar 22, 2023 at 11:52

1 Answer 1

4

Sorry for not updating the answer.

Yes, i have finally figured out that it is one of our DBA that changed the source of ltree and recompile it with supporting the dash(-) char. We have a single table with more than 6B records.

5
  • Since you have more than 6B records, is there any problem with including the dash? Or is everything good? Just wanted to know why the label restriction was put in the first place. And also do you have the patch hosted somewhere? Thanks.
    – Charizard_
    Commented Dec 3, 2015 at 11:19
  • 1
    @Charizard Yes, everything is good, i do not know why the author of ltree do not have it in the original source code. The patch is very simple. You can have a look at the source code, i.e., the 83 line of ltree.h
    – andy
    Commented Dec 6, 2015 at 8:16
  • 1
    I'll try to submit patch request and wish it gets accepted
    – caub
    Commented May 19, 2017 at 10:28
  • just wonder if someone has re-compiled it as a separate extension or if there's any tutorial about how to re-compile the ltree module, we want to support the dash as well
    – Deo Leung
    Commented Sep 7, 2021 at 3:40
  • 1
    FYI Postgres 16 will include support for - via this patch which was merged recently.
    – Tim Bunce
    Commented Mar 22, 2023 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.