使用 PostgreSQLCopyHelper 时如何应用 ST_GeomFromText() 函数来格式化文本 (https://github.com/PostgreSQLCopyHelper/PostgreSQLCopyHelper)

How to apply ST_GeomFromText() function to format text when using PostgreSQLCopyHelper (https://github.com/PostgreSQLCopyHelper/PostgreSQLCopyHelper)

INSERT INTO geotable (geometrydata) values (ST_GeomFromGeoJSON(@geometrydata));

如何在 C# 代码中使用 PostgreSQLCopyHelper 运行 将上述插入语句插入到 posgresql 数据库中。试图做这样的事情。

var copyHelper = new PostgreSQLCopyHelper<GeoData>("geotable ") .Map("geometrydata", x => x.geometrydata, NpgsqlDbType.Geometry);

geometrydata 是如下所示的字符串。

`var geometrydata = "{\"type\":\"Polygon\",\"coordinates\":[[[-81.800007507357,24.491670214271,0.0],[-81.800007507357,24.500003548802,0.0],[-81.7916741718259,24.500003548802,0.0],[-81.7916741718259,24.491670214271,0.0],[-81.800007507357,24.491670214271,0.0]]]}"`

如何在使用 PostgreSQLCopyHelper 时使用 postgis 函数格式化数据。 (https://github.com/PostgreSQLCopyHelper/PostgreSQLCopyHelper )

使用 COPY 加载数据时不能调用函数。

如果您确实需要它,则必须在 table 上创建一个视图,并在视图上使用 INSTEAD OF 触发器,将 suitable 处理过的行插入到table.

将数据加载到分段 table 并在所有行上使用 UPDATE 执行转换可能会更好。