Skip to content

Support DESC INDEX #2416

@MC-XiaoHei

Description

@MC-XiaoHei

It would be great to be able to do something like this with an API

CREATE INDEX IF NOT EXISTS unit_operations_time_idx ON unit_operations (time DESC);

for now, I need to use some code like this to implement this:

object UnitOperationsTable : LongIdTable("unit_operations") {
    val unitId = integer("unit_id")
    val time = defaultNowTimestampTz("time")

    init {
        index(customIndexName = "unit_operations_unit_id_idx", columns = arrayOf(unitId))
        try {
            transaction {
                exec("CREATE INDEX IF NOT EXISTS unit_operations_time_idx ON unit_operations (time DESC);")
            }
        } catch (_: ExposedSQLException) {
            // when run first time, the table may not exist, so ignore the error
        }
    }
}

and you see, index wil not created at the first time.
I'd like some other alternative way to do this

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions