I m facing the same issue like this one: <https://...
# exposed
k
I m facing the same issue like this one: https://stackoverflow.com/questions/65002107/how-can-i-call-a-sequence-nextval-using-kotlin-exposed Is there a way how to get nextval from sequence without making it a part of some other query?
I've implemented this workaround now:
Copy code
open class SequenceNextLongValQuery(private val sequence: Sequence): Statement<Long>(StatementType.SELECT, listOf()) {
    private val transaction get() = TransactionManager.current()
    override fun arguments(): Iterable<Iterable<Pair<IColumnType, Any?>>> = emptyList()
    override fun prepareSQL(transaction: Transaction): String = prepareSQL(QueryBuilder(true))

    private fun prepareSQL(builder: QueryBuilder): String {
        builder {
            append("SELECT ")
            append(sequence.nextLongVal())
        }

        return builder.toString()
    }

    override fun PreparedStatementApi.executeInternal(transaction: Transaction): Long? {
        val resultSet = executeQuery()
        return if (resultSet.next()) resultSet.getLong(1) else null
    }

    fun execute(): Long? = super.execute(transaction)
}

fun Sequence.selectNextLongVal() = SequenceNextLongValQuery(this).execute()
...
Copy code
val userIdSequence = Sequence("app_user_user_id_seq")
val nextUserId = userIdSequence.selectNextLongVal()
but I am not sure if there isn't any better way.. Also I don't know how to generalize it properly since there are two different implementations of NextVal:
IntNextVal
and
LongNextVal