使用“结束”作为Ruby on Rails的(MySQL的)列名 [英] Using 'end' as column name in Ruby on Rails (MySQL)

查看:151
本文介绍了使用“结束”作为Ruby on Rails的(MySQL的)列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模型,一个结束列(日期时间格式),却意外地发现Heroku的崩溃和烧伤不合逻辑的活动记录错误,每当我试图引用的列的查询。我花了两个小时试图调试非常简单的查询,在此之后我改名为列end_at和我所有的问题消失了。

I had an model with an "end" column (datetime format), only to discover that Heroku crashes and burns with illogical Active Record errors whenever I attempted to reference the column in a query. I spent two hours trying to debug the extremely simple query, after which point I renamed the column to "end_at" and all of my problems disappeared.

有其他人遇到此问题?我很好奇,这背后的推理,并希望我们能帮助其他人避免犯同样的错误。类似的问题已经被问之前,而是一个明确的答案并不presented

Has anybody else experienced this issue? I'm curious of the reasoning behind this and hope that we can help others avoid the same mistake. A similar question has been asked before, but a clear answer was not presented.

推荐答案

BEGIN和END在Oracle和SQL Server保留字,但不知道为什么的MySQL的不认为他们这样

BEGIN and END are reserved words in Oracle and SQL Server, but not sure why MySQL doesn't consider them as such.

不过这PGError似乎表明数据库引擎本身(而不是任何Ruby相关的运行时间)的确拒绝了,因为末查询。

However that PGError would appear to indicate that the database engine itself (and not any Ruby-related runtime) has indeed rejected the query because of the "end".

保留字(含空格的名称)可以使用,如果引用 - 也许是活动记录不引用标识符在其中生成的SQL

Reserved words (and names containing spaces) can be used if quoted - perhaps Active Record didn't quote the identifiers in the SQL which was generated.

我想看看在日志中的MySQL(http://dev.mysql.com/doc/refman/5.5/en/query-log.html),看看生成报表。

I would look at the log in MySQL (http://dev.mysql.com/doc/refman/5.5/en/query-log.html) and see the statements generated.

而自从PGError意味着PostgreSQL和你提到的Heroku(PostgreSQL 8.3版本) - 我想这是因为END确实是一个保留字PostgreSQL中:的 http://www.postgresql.org/docs/8.3/static/sql-keywords-appendix.html

And since the PGError means PostGreSQL and you mentioned Heroku (PostgreSQL 8.3) - I think this is because END is indeed a reserved word in PostgreSQL: http://www.postgresql.org/docs/8.3/static/sql-keywords-appendix.html

http://www.petefreitag.com/tool​​s/sql_reserved_words_checker/?word=结束

这篇关于使用“结束”作为Ruby on Rails的(MySQL的)列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆