pablo.pazos
08/19/2025, 9:30 PMgaolei
08/19/2025, 9:33 PMpablo.pazos
08/19/2025, 9:34 PMgaolei
08/19/2025, 9:34 PMpablo.pazos
08/19/2025, 9:35 PMgaolei
08/19/2025, 9:36 PMstartTime index: 'idx_event_start_time'
Emm, is this what you ask ??gaolei
08/19/2025, 9:36 PMpablo.pazos
08/19/2025, 9:36 PMpablo.pazos
08/19/2025, 9:37 PMgaolei
08/19/2025, 9:38 PMpablo.pazos
08/19/2025, 9:38 PMCREATE INDEX x_idx ON your_table ((DATE(x)));pablo.pazos
08/19/2025, 9:38 PMpablo.pazos
08/19/2025, 9:39 PMDate value
static mapping = {
value index: 'value_dt_idx', type: 'date'
}gaolei
08/19/2025, 9:40 PMpablo.pazos
08/19/2025, 9:41 PMPablo Pazos
08/20/2025, 12:04 AMmoogtrain
08/20/2025, 5:14 PMstatic mapping = { someDate formula: “DATE(some_date_time) }. This makes GORM include that formula in the query for the domain object.
Hibernate does not support declaring indexes on expression/formulas. Just have your schema setup process run the DDL.pablo.pazos
08/20/2025, 5:57 PMmoogtrain
08/22/2025, 3:04 AMDATE(timestamp_field) or price * qty into a field, you can use “formula” on mapping closure:
class YourTable {
static mapping = {
dateSubmitted formula: "DATE(instant_submitted)" // note the underscore. This is interpreted by SQL database.
}
int id
Date instantSubmitted // this is a column
LocalDate dateSubmitted // this is not a column, because of formula above.
}
def row = YourTable.findById(1)
// SQL executed is something like: SELECT id, instant_submitted, DATE(instant_submitted) AS date_submitted_1 FROM your_table WHERE id = ?
row.instantSubmitted // YYYY-MM-DD HH:mm:SS
row.dateSubmitted // YYYY-MM-DD
Now, this doesn’t answer your later question about functional index. I was trying to address that in the latter half of my message.
Hibernate (and by extension GORM) only supports referencing column names for indexes. You cannot declare an index based on expressions or functions. So, to create such indexes, it has to done manually, either in the DB or with Liquibase/Flyway.
Here is the relevant SO answer that I found about this: https://stackoverflow.com/questions/33766647/jpa-2-1-index-annotation-for-columns-with-a-function