Обсуждение: Feature request for INITCAP() function
It would be great if there was a way to set exceptions to the 'word' delimiter list used in the INITCAP() function. For example, I have hyphenated words like blue-green or possessives and contractions like don't and cat's tail
These become Blue-Green, Don'T and Cat'S Tail.
Being able to pass in a set of delimiter exceptions like hyphen and single quote would make this function much more useful for our specific use cases.
These become Blue-Green, Don'T and Cat'S Tail.
Being able to pass in a set of delimiter exceptions like hyphen and single quote would make this function much more useful for our specific use cases.
Thanks for considering,
Jeff
-- Jeff Gerbracht
Cornell Lab of Ornithology
Cornell Lab of Ornithology
On Thu, 2023-11-30 at 21:08 -0500, Jeff Gerbracht wrote: > It would be great if there was a way to set exceptions to the 'word' delimiter list used in > the INITCAP() function. For example, I have hyphenated words like blue-green or > possessives and contractions like don't and cat's tail > These become Blue-Green, Don'T and Cat'S Tail. > > Being able to pass in a set of delimiter exceptions like hyphen and single quote would make > this function much more useful for our specific use cases. That would pretty quickly drift into locale-dependent rules. Such a function would be even more special-case than the current "initcap()", which is already pretty specific to certain languages. I don't know if there is enough value for the general public in it. But it should be easy to implement it yourself, for example in PL/pgSQL. Why don't you try that? Yours, Laurenz Albe
Jeff Gerbracht wrote:
> It would be great if there was a way to set exceptions to the 'word'
> delimiter list used in the INITCAP() function. For example, I have
> hyphenated words like blue-green or possessives and contractions like
> don't and cat's tail
> These become Blue-Green, Don'T and Cat'S Tail.
An ICU collation may produce better results for this:
select initcap('blue-green don''t cat''s tail' COLLATE "en-x-icu");
initcap
-----------------------------
Blue-Green Don't Cat's Tail
With hyphens, it's not clear what the results should be.
Looking at the IMDb movies database [1] for instance, titles have
a mix of upper and lower case following the hyphen, even within the
same english title:
Hell-to-Pay Austin
The Co-respondent
A Pit-boy's Romance
A Cowboy's Mother-in-Law
Our Parents-In-Law
The Good-for-Nothing
When the Fire-Bells Rang
The post-millennial wave
...
[1] https://datasets.imdbws.com/
Best regards,
--
Daniel Vérité
https://postgresql.verite.pro/
Twitter: @DanielVerite