value As
Returns a field value from a result with exactly one row. Useful for getting the result of an aggregating function.
Parameters
name
the name of the field to extract.
serializer
for converting the field value to the requested type. Defaults to the QueryRow's serializer.
Type Parameters
T
the serializer reads the field value as this type.
Throws
if there is more than one result row
if there is no field with the given name
Samples
// Single-value query with anonymous result
val count = cluster
.query("select count(*) from `travel-sample`")
.execute()
.valueAs<Long>() // uses default name "$1"Content copied to clipboard
// Single-value query with named result
val count = cluster
.query("select count(*) as count from `travel-sample`")
.execute()
.valueAs<Long>("count")Content copied to clipboard