Search code examples
postgresqlkotlinkotlin-exposed

Kotlin Exception in thread "main" org.postgresql.util.PSQLException: ERROR


I'm using Kotlin Exposed for ORM in my Web application. I have an Entity User and it was created in the database(PostgreSQL) I have a problem when I want to find a value in a table(User), show me this Error

Exception in thread "main" org.postgresql.util.PSQLException: ERROR: column users.emailSituation does not exist Hint: Perhaps you meant to reference the column "users.emailsituation". Position: 59

My database is postgresql

User Entity:

object Users : IntIdTable() {
    val name = text("name").index()
    val family = text("family").index()
    val email = text("email").index()
    val emailSituation = bool("emailSituation")
    val mobile = long("mobile").index()
}

class User(id: EntityID<Int>) : IntEntity(id) {
    companion object : IntEntityClass<User>(Users)

    var name by Users.name
    var family by Users.family
    var email by Users.email
    var emailSituation by Users.emailSituation
    var mobile by Users.mobile
}

find a value :

transaction {
        logger.addLogger(StdOutSqlLogger)
 println("User: ${User.find { Users.mobile eq 87654 }.joinToString {it.name}}")
    }

How can I solve it?


Solution

  • The error seems to indicate that it is trying to query for a column called emailSituation, but only emailsitutation is available. This might have to do with how the query is ultimately being constructed by your library. Postgres will generally accept anything and lowercase it for column names unless you quote it (which is probably out of your control). To get around this, try lowercasing the name of the column you map to:

    Change:

    val emailSituation = bool("emailSituation")
    

    To:

    val emailSituation = bool("emailsituation")
                                    ^
                                    +-- That's the difference