Well, I found a viable solution:
- I recreated the tree_encodings table with the same collating sequence used by Postgres (select code from tree_encodings order by code)
- I modified the next_sortkey function using the first character in the collating sequence instead of '0' to denote the first key of any level
Now things run smoothly.
Claudio Pasolini