Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for collation #975

Open
thibautd opened this issue Mar 30, 2024 · 1 comment
Open

Add support for collation #975

thibautd opened this issue Mar 30, 2024 · 1 comment

Comments

@thibautd
Copy link

thibautd commented Mar 30, 2024

Hello,

I don't know for Cockroach DB, but I know that PostgreSQL supports collations. This is nice feature that replaces existing extensions like citext in order to have case insensitive columns (like an email).

I think we could have a collation= property to Varchar/Text columns. Collations can be created by a raw migration, but any better system would be welcome. Of course it could work with any collation, not only case insensitive.

Currently I implemented this using a Varchar subclass, as a proof of concept:

class VarcharCaseInsensitive(Varchar):
    @property
    def column_type(self):
        return super().column_type + " COLLATE case_insensitive"

And I added this collation using a migration:

async def create_ci_collation():
    await RawTable.raw(
        "CREATE COLLATION case_insensitive (provider = icu, locale = 'und-u-ks-level2', deterministic = false);"
    )

async def drop_ci_collation():
    await RawTable.raw("DROP COLLATION IF EXISTS case_insensitive")

manager.add_raw(create_ci_collation)
manager.add_raw_backwards(drop_ci_collation)

I'm new to Piccolo and I'm discovering the code base, their might be a better way of doing this.

@dantownsend
Copy link
Member

It's an interesting idea.

It wouldn't be too hard to add collate as an argument to the order_by method. We have OrderByRaw, so it is kind of possible now.

I'm not sure if CockroachDB supports collate - i would have to check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants