为什么当我尝试在 MariaDB 数据库上创建此函数(使用点数据类型)时出现此错误?
Why I obtain this error when I try to create this funcion (that use point data type) on a MariaDB database?
我不是很喜欢数据库,我对执行本教程有以下疑问:https://mariadb.org/jquery-and-gis-distance-in-mariadb/
所以基本上我的疑问与这个 SQL 声明有关,该声明创建了一个函数来计算 MariaDB 数据库上两个 点 之间的距离:
CREATE FUNCTION earth_circle_distance(point1 point, point2 point) RETURNS double
DETERMINISTIC
begin
declare lon1, lon2 double;
declare lat1, lat2 double;
declare td double;
declare d_lat double;
declare d_lon double;
declare a, c, R double;
set lon1 = X(GeomFromText(AsText(point1)));
set lon2 = X(GeomFromText(AsText(point2)));
set lat1 = Y(GeomFromText(AsText(point1)));
set lat2 = Y(GeomFromText(AsText(point2)));
set d_lat = radians(lat2 - lat1);
set d_lon = radians(lon2 - lon1);
set lat1 = radians(lat1);
set lat2 = radians(lat2);
set R = 6372.8; -- in kilometers
set a = sin(d_lat / 2.0) * sin(d_lat / 2.0) + sin(d_lon / 2.0) * sin(d_lon / 2.0) * cos(lat1) * cos(lat2);
set c = 2 * asin(sqrt(a));
return R * c;
end
我的问题是执行前面的语句时出现以下错误消息:
Error
----------------------------------------------------
Static analysis:
2 errors were found during analysis.
1. Unrecognized data type. (near "point" at position 45)
2. Unrecognized data type. (near "point" at position 59)
SQL query:
CREATE FUNCTION earth_circle_distance(point1 point, point2 point) RETURNS double DETERMINISTIC begin declare lon1, lon2 double
MySQL said:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 4
PhpMyAdmin 在上一条语句的第一行用 2 个红色标记标记 point 数据类型:
CREATE FUNCTION earth_circle_distance(point1 point, point2 point) RETURNS double
但我不认为这可能是真正的问题(我认为这可能是 PhpMyAdmin 不知道的事情)因为它也将此 cration 查询标记为红色:
CREATE TABLE gis_point (g POINT);
但它工作正常,没有错误并正确创建 table。
所以,哪里错了?可能取决于 PhpMyAdmin 或者我错过了什么?
这个函数应该存储在哪里?
更改分隔符。否则函数定义在第一个 ;
处结束,这会使它不完整。
delimiter ||
CREATE FUNCTION earth_circle_distance(point1 point, point2 point) RETURNS double
DETERMINISTIC
begin
declare lon1, lon2 double;
declare lat1, lat2 double;
declare td double;
declare d_lat double;
declare d_lon double;
declare a, c, R double;
set lon1 = X(GeomFromText(AsText(point1)));
set lon2 = X(GeomFromText(AsText(point2)));
set lat1 = Y(GeomFromText(AsText(point1)));
set lat2 = Y(GeomFromText(AsText(point2)));
set d_lat = radians(lat2 - lat1);
set d_lon = radians(lon2 - lon1);
set lat1 = radians(lat1);
set lat2 = radians(lat2);
set R = 6372.8; -- in kilometers
set a = sin(d_lat / 2.0) * sin(d_lat / 2.0) + sin(d_lon / 2.0) * sin(d_lon / 2.0) * cos(lat1) * cos(lat2);
set c = 2 * asin(sqrt(a));
return R * c;
end
||
delimiter ;
我不是很喜欢数据库,我对执行本教程有以下疑问:https://mariadb.org/jquery-and-gis-distance-in-mariadb/
所以基本上我的疑问与这个 SQL 声明有关,该声明创建了一个函数来计算 MariaDB 数据库上两个 点 之间的距离:
CREATE FUNCTION earth_circle_distance(point1 point, point2 point) RETURNS double
DETERMINISTIC
begin
declare lon1, lon2 double;
declare lat1, lat2 double;
declare td double;
declare d_lat double;
declare d_lon double;
declare a, c, R double;
set lon1 = X(GeomFromText(AsText(point1)));
set lon2 = X(GeomFromText(AsText(point2)));
set lat1 = Y(GeomFromText(AsText(point1)));
set lat2 = Y(GeomFromText(AsText(point2)));
set d_lat = radians(lat2 - lat1);
set d_lon = radians(lon2 - lon1);
set lat1 = radians(lat1);
set lat2 = radians(lat2);
set R = 6372.8; -- in kilometers
set a = sin(d_lat / 2.0) * sin(d_lat / 2.0) + sin(d_lon / 2.0) * sin(d_lon / 2.0) * cos(lat1) * cos(lat2);
set c = 2 * asin(sqrt(a));
return R * c;
end
我的问题是执行前面的语句时出现以下错误消息:
Error
----------------------------------------------------
Static analysis:
2 errors were found during analysis.
1. Unrecognized data type. (near "point" at position 45)
2. Unrecognized data type. (near "point" at position 59)
SQL query:
CREATE FUNCTION earth_circle_distance(point1 point, point2 point) RETURNS double DETERMINISTIC begin declare lon1, lon2 double
MySQL said:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 4
PhpMyAdmin 在上一条语句的第一行用 2 个红色标记标记 point 数据类型:
CREATE FUNCTION earth_circle_distance(point1 point, point2 point) RETURNS double
但我不认为这可能是真正的问题(我认为这可能是 PhpMyAdmin 不知道的事情)因为它也将此 cration 查询标记为红色:
CREATE TABLE gis_point (g POINT);
但它工作正常,没有错误并正确创建 table。
所以,哪里错了?可能取决于 PhpMyAdmin 或者我错过了什么? 这个函数应该存储在哪里?
更改分隔符。否则函数定义在第一个 ;
处结束,这会使它不完整。
delimiter ||
CREATE FUNCTION earth_circle_distance(point1 point, point2 point) RETURNS double
DETERMINISTIC
begin
declare lon1, lon2 double;
declare lat1, lat2 double;
declare td double;
declare d_lat double;
declare d_lon double;
declare a, c, R double;
set lon1 = X(GeomFromText(AsText(point1)));
set lon2 = X(GeomFromText(AsText(point2)));
set lat1 = Y(GeomFromText(AsText(point1)));
set lat2 = Y(GeomFromText(AsText(point2)));
set d_lat = radians(lat2 - lat1);
set d_lon = radians(lon2 - lon1);
set lat1 = radians(lat1);
set lat2 = radians(lat2);
set R = 6372.8; -- in kilometers
set a = sin(d_lat / 2.0) * sin(d_lat / 2.0) + sin(d_lon / 2.0) * sin(d_lon / 2.0) * cos(lat1) * cos(lat2);
set c = 2 * asin(sqrt(a));
return R * c;
end
||
delimiter ;