gpt4 book ai didi

php - MYSQL 列的默认值无效

转载 作者:行者123 更新时间:2023-11-30 23:32:07 25 4
gpt4 key购买 nike

我正在使用 MySQL 的地理空间扩展。在 MyISAMlistings 中有一个 GEOMETRYp 和 2 个 float latlng 列。 p 中的值使用 UPDATE listings SET p = POINT(lat, lng); 设置。

问题:现在我想在 p 列上设置空间索引。当我尝试时:

ALTER TABLE listings ADD SPATIAL INDEX(p);

也尝试过:

CREATE SPATIAL INDEX sp_index ON listings (p);

两次,我都收到错误 error : All parts of a SPATIAL index must be NOT NULL

所以(使用 Navicat)我尝试制作 col p NOT NULL,但它需要一个默认值。我应该为此使用什么默认值?我尝试使用 '' 作为默认值,但它给出了错误 invalid default value for 'p'

我尝试将 p 的默认值设置为 POINT(0,0) 但出现错误 BLOB/TEXT column 'p' can't有默认值

我应该如何处理这个问题来创建空间索引?谢谢!

编辑

在运行查询 ALTER TABLE listings CHANGE p p POINT NOT NULL 后,运行 ADD SPATIAL INDEX(p) 会导致一个奇怪的错误 Lost connection to MySQL server during query 。其他不涉及创建索引的查询工作正常,即。 SELECT * FROM 列表

结果来自SHOW CREATE TABLE listings

CREATE TABLE `listings` (
`listing_id` int(8) NOT NULL AUTO_INCREMENT,
`url` varchar(255) DEFAULT NULL,
`website_city` varchar(32) DEFAULT NULL,
`website` varchar(32) DEFAULT NULL,
`price` int(7) DEFAULT NULL,
`price_per_br` int(7) DEFAULT NULL,
`bedroom` int(2) DEFAULT NULL,
`bathroom` int(2) DEFAULT NULL,
`fee` varchar(10) DEFAULT NULL,
`address_1` varchar(255) DEFAULT NULL,
`address_2` varchar(255) DEFAULT NULL,
`city` varchar(64) DEFAULT NULL,
`state` varchar(32) DEFAULT NULL,
`postal` int(6) DEFAULT NULL,
`retrival_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`post_timestamp` timestamp NULL DEFAULT NULL,
`lat` float(10,6) DEFAULT NULL,
`lng` float(10,6) DEFAULT NULL,
`p` point NOT NULL,
`description` text,
`img_subpath` varchar(15) DEFAULT NULL,
`photos` text,
`reply_email` varchar(255) DEFAULT NULL,
`phone` varchar(16) DEFAULT NULL,
`has_dishwasher` tinyint(1) DEFAULT NULL,
`has_laundry` tinyint(1) DEFAULT NULL,
`has_fireplace` tinyint(1) DEFAULT NULL,
`has_elevator` tinyint(1) DEFAULT NULL,
`has_balcony` tinyint(1) DEFAULT NULL,
`has_deck` tinyint(1) DEFAULT NULL,
`has_backyard` tinyint(1) DEFAULT NULL,
`has_parking` tinyint(1) DEFAULT NULL,
`has_gym` tinyint(1) DEFAULT NULL,
`has_pool` tinyint(1) DEFAULT NULL,
`cats_ok` tinyint(1) DEFAULT NULL,
`dogs_ok` tinyint(1) DEFAULT NULL,
PRIMARY KEY (`listing_id`),
KEY `lat lng` (`lat`,`lng`,`price`,`price_per_br`,`bedroom`,`bathroom`,`post_timestamp`) USING BTREE,
KEY `spatial` (`p`(25))
) ENGINE=MyISAM AUTO_INCREMENT=589605 DEFAULT CHARSET=latin1

我将 p 转换回 GEOMETRY,运行查询以将索引添加到 p 并得到一个新错误 Cannot从您发送到 GEOMETRY 字段的数据中获取几何对象

最佳答案

本页InformIT: Data Types in MySQL声称空间列不能有 DEFAULT 值,但我无法在 MySQL 文档中找到该信息:

3.2.3 Specifying Column Default Values

For all but BLOB and TEXT types, spatial types, or columns with the AUTO_INCREMENT attribute, you can specify a DEFAULT def_value clause to indicate that ...

在我的 5.1 盒子中测试显示与您的相同的错误。所以这个说法可能是正确的。

关于php - MYSQL 列的默认值无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10045022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com