Inserting a polygon into MySQL

Viewed 30

I have a MySQL 8 table with a column called "coordinates" of type "polygon".

I am trying to insert a set of coordinates into it, like so:

INSERT INTO contract (coordinates) 
VALUES (POLYGON(
(34.786166422784426, 32.162676265661624), 
(34.720248454034426, 32.01024096292725), 
(34.816378825128176, 31.973162105505374), 
(34.86993717473755, 32.1338371543335), 
(34.786166422784426, 32.162676265661624))
)

which is giving me a "column count doesn't match value count at row 1" error.

Why is this? How do I properly format this query? And how can I explicitly pass an ESRI with it?

This, by the way, works fine:

INSERT INTO contract (coordinates, smart_contract_version_id) 
VALUES (ST_GeomFromText('POLYGON((   34.786166422784426 32.162676265661624 , 34.720248454034426 32.01024096292725 , 34.816378825128176 31.973162105505374 , 34.86993717473755 32.1338371543335 , 34.786166422784426 32.162676265661624  ))', 4326), 1)
1 Answers

You are inserting wrong .. You don't need the sets of parens .. Note double parens are INTENTIONAL .. AND the X / Y is denoted by a space .. Not a comma. If it works without the "double parens" It's because you don't have any insets -- "holes" etc ..

POLYGON((
   34.786166422784426 32.162676265661624, 
   34.720248454034426 32.01024096292725, 
   34.816378825128176 31.973162105505374, 
   34.86993717473755 32.1338371543335, 
   34.786166422784426 32.162676265661624
))
Related