mysql - 无法将字符串插入 MySQL 文本列

标签 mysql syntax text insert

<分区>

出于某种原因,当我写入“文本”类型的列时,我的查询搞砸了。这是一个例子:

Describe messages;

Field         Type          Null  Key  Default  Extra
id            int(11)       NO    PRI  NULL     auto_increment
title         varchar(255)  YES        NULL 
body          text          YES        NULL 
to            text          YES        NULL 
content_type  varchar(255)  YES        NULL 
is_sms        tinyint(1)    YES        NULL 
user_id       int(11)       YES        NULL 
created_at    datetime      YES        NULL 
updated_at    datetime      YES        NULL

然后我尝试插入:

INSERT INTO messages (id,title,body,to) VALUES ('1','Test Message','This is a test message. This is a test message. This is a test message. This is a test message.', 'an email' );

出于某种原因,这会导致一般的 MySQL 语法错误。如果我从查询中删除“to”列及其对应的值,则查询工作正常。

有什么想法吗?

最佳答案

'to' 是 MySQL 中的保留关键字。您需要重命名您的列。

http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html

但是,如果您引用保留字,则允许将其用作标识符。

http://dev.mysql.com/doc/refman/5.1/en/identifiers.html

关于mysql - 无法将字符串插入 MySQL 文本列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/752277/

相关文章:

java - 在 GlassFish 中为远程数据库创建 JDBC 连接池

c# - 对 BigIntegers 列表求和

android 显示大量文本

Python bool 表达式和或

python - Tkinter 文本小部件。取消选择文本

python /元素树 : Parsing inline elements w/respect to surrounding text?

python - 编程错误: not all arguments converted during string formatting

Mysql 5.6.12 错误 : error 1356 when using order by alias in a view definition

mysql - SQL : select values between multiple ranges