Код: Выделить всё
alter table tbl_address
add column location POINT GENERATED ALWAYS AS (ST_SRID(POINT(longitude, latitude), 4326)) STORED NOT NULL;
Код: Выделить всё
CREATE SPATIAL INDEX idx_location ON tbl_address (location);
0 row(s) affected, 1 warning(s): 3674 The spatial index on column 'location' will not be used by the query optimizer since the column does not have an SRID attribute. Consider adding an SRID attribute to the column. Records: 0 Duplicates: 0 Warnings: 1
Как заставить это работать? Было бы здорово обновлять местоположение при изменении долготы/широты. Действительно ли мне нужно реализовать триггер? Я использую MySQL 8.
Спасибо!
Изменить:
Моя версия mysql — 8.0.43-0ubuntu0.22.04.1, и это тестовая таблица, которую я использую:
Код: Выделить всё
CREATE TABLE IF NOT EXISTS tbl_address
(
address_id int not null auto_increment,
latitude DECIMAL(9,2) NOT NULL default 0,
longitude DECIMAL(9,2) NOT NULL default 0,
location POINT not null SRID 4326,
Primary Key (address_id)
);
Подробнее здесь: https://stackoverflow.com/questions/798 ... -attribute
Мобильная версия