https://kotlinlang.org logo
#exposed
Title
# exposed
t

Tasos Stamadianos

01/24/2019, 12:18 AM
Hi there, I'm using a database with
PostGIS
support, and I'd like to call a
PostGIS
function during an insert, but I really can't figure out how to do this. I've seen examples involving
ExpressionWithColumnType
, but nothing that actually uses this function during an
insert
in a
transaction
. Some relevant code:
Copy code
abstract class SQLFunction<T>(override val columnType: IColumnType) : ExpressionWithColumnType<T>()

class ST_Centroid(private val poly: MultiPolygon): SQLFunction<Point>(PointColumnType()) {
    override fun toSQL(queryBuilder: QueryBuilder) = "ST_Centroid($poly)"
}
I'm trying to do this now:
[DbFields.center] = ST_Centroid(boundaryPoly)
where
boundaryPoly
is a PostGIS multipolygon. Any help would be greatly appreciated 🙂
t

tapac

01/24/2019, 9:51 AM
Try:
Copy code
FooTable.insert{
  it.update(FooTable.point, ST_Centroid(polygon))
}
t

Tasos Stamadianos

01/27/2019, 12:55 AM
Thanks!
58 Views