Hi there, I'm using a database with `PostGIS` supp...
# exposed
t
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
Try:
Copy code
FooTable.insert{
  it.update(FooTable.point, ST_Centroid(polygon))
}
t
Thanks!