MySQL Spatial Geometry – Creating Polygon from Point Datatype

geometryMySQLspatial

I have a table like this:

CREATE TABLE `aois` (
  `aois_id` int(11) NOT NULL DEFAULT '0',
  `WS_A` point DEFAULT NULL,
  `WS_B` point DEFAULT NULL,
  `WS_C` point DEFAULT NULL,
  `WS_D` point DEFAULT NULL,
  `DB_A` point DEFAULT NULL,
  `DB_B` point DEFAULT NULL,
  `DB_C` point DEFAULT NULL,
  `DB_D` point DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

Now i want to create a polygons from the points:

SELECT aois_id,
polygon((WS_A, WS_B, WS_C, WS_D, WS_A)) as geom
FROM aois;

But i always get the error message:

Operand should contain 1 column(s)

(I'm using MySQL Server Version 8.0.16 on Windows 10, if that is of any importance.)

Can anyone point me in the right direction?

Thanks a lot!

Best Answer

SELECT aois_id,
polygon(
   linestring(WS_A, WS_B, WS_C, WS_D, WS_A)
) as geom
FROM aois;