ent / ent

An entity framework for Go
https://entgo.io
Apache License 2.0
15.42k stars 912 forks source link

postgres functional index support #3258

Open Liooo opened 1 year ago

Liooo commented 1 year ago

Summary 💡

Would be great if ent supported functional index creation like:

CREATE INDEX test1_lower_col1_idx ON test1 (lower(col1));

https://www.postgresql.org/docs/7.3/indexes-functional.html

Motivation 🔦

To have an index without adding a new column.

Ambroos commented 1 year ago

Atlas has index expression support which does just that: https://atlasgo.io/atlas-schema/sql-resources#index-expressions .

It would be really cool to have this available in Ent too (when using Atlas). Main use case on my end is to have more control over JSONB indexing (for example only indexing a specific field inside an object).

Locter9001 commented 1 year ago

Atlas has index expression support which does just that: https://atlasgo.io/atlas-schema/sql-resources#index-expressions .

It would be really cool to have this available in Ent too (when using Atlas). Main use case on my end is to have more control over JSONB indexing (for example only indexing a specific field inside an object).

how to do it? I don't understand, can atlas be integrated with ent?

use ent to generate the sql file and use atlas to migrate it afterwards?

emoss08 commented 3 months ago

Atlas has index expression support which does just that: https://atlasgo.io/atlas-schema/sql-resources#index-expressions . It would be really cool to have this available in Ent too (when using Atlas). Main use case on my end is to have more control over JSONB indexing (for example only indexing a specific field inside an object).

how to do it? I don't understand, can atlas be integrated with ent?

use ent to generate the sql file and use atlas to migrate it afterwards?

The issue with this is if you modify the index in the generated SQL file and generate again, it will drop the index.

marwan-at-work commented 1 week ago

Just ran into this. The docs here mention that there are no APIs for defining a functional index: https://entgo.io/docs/schema-indexes#functional-indexes

cc @a8m 👋🏼 is there a reason for the above? There are APIs for almost everything else :)