Hello! I have a query that fails when upgrading fr...
# exposed
r
Hello! I have a query that fails when upgrading from exposed 1.5.0 to 1.6.0 (more details in thread!)
👀 1
This is the simplified model:
Copy code
@Serializable
@JsonClassDiscriminator("type")
sealed interface LicenseCreationSource {
    /// some members here
}

data object Licenses : UUIDTable() {
    val isDeleted = bool("is_deleted").default(false)
    val creationSource = jsonb<LicenseCreationSource>("creation_source", Json.Default).nullable()
}
This is the query:
Copy code
val creationSourceType = Licenses.creationSource.extract<String>("type")

Licenses
    .select(Licenses.id.count(), creationSourceType)
    .where { Licenses.isDeleted eq false }
    .andWhere { creationSourceType.isNotNull() }
    .groupBy(creationSourceType)
It fails with the following message:
Copy code
ERROR: column "licenses.creation_source" must appear in the GROUP BY clause or be used in an aggregate function
  Position: 52
If I look at the statements logged by postgres, with exposed 1.5.0 the query looks like this:
Copy code
SELECT COUNT(licenses.id), JSONB_EXTRACT_PATH_TEXT(licenses.creation_source, 'type') FROM licenses WHERE (licenses.is_deleted = $1) AND (JSONB_EXTRACT_PATH_TEXT(licenses.creation_source, 'type') IS NOT NULL) GROUP BY JSONB_EXTRACT_PATH_TEXT(licenses.creation_source, 'type')
with 1.6.0, it looks like this:
Copy code
SELECT COUNT(licenses.id), JSONB_EXTRACT_PATH_TEXT(licenses.creation_source, $1) FROM licenses WHERE (licenses.is_deleted = $2) AND (JSONB_EXTRACT_PATH_TEXT(licenses.creation_source, $3) IS NOT NULL) GROUP BY JSONB_EXTRACT_PATH_TEXT(licenses.creation_source, $4)
I suspect the parameters are the issue, they're not recognized as the same column? Not sure how to address this or if this is expected behaviour.