ruby-on-rails - 在 Rails 中排序 : SQLite vs PostgreSQL

标签 ruby-on-rails postgresql sqlite

当我在 Rails 5 中使用 sqlite 作为开发数据库按列(id 类型 INT)排序时,它按预期排序(1、2、3、4 ...),但在我的生产环境(PostgreSQL ) 导致意外行为(1, 101, 102,...2, 201,...)等等。

如果我按照 PostgreSQL (MyModel.order('id::integer DESC')) 格式化订单,那么它在 PostgreSQL 中工作正常,但在我的开发 sqlite 环境中不再工作。

我是不是忽略了什么?我对编程很陌生。

最佳答案

Your data types are messed up. What does .schema your_table say in the sqlite3 shell? How about \d your_table from psql? Keep in mind that SQLite has a very loose value-based type system rather than a column-based one (i.e. you can put a string in a column declared as an integer and SQLite won't say a thing). – mu is too short

关于ruby-on-rails - 在 Rails 中排序 : SQLite vs PostgreSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41469889/

相关文章:

jquery - 在 rails 中通过 remote_function 中的表单生成器?

sql - PostgreSQL 中的约束和断言

java - 如何在java中的sqlite db中获取并自动输入当前日期?

ruby-on-rails - Rails 3 和 HTML 5 微数据

ruby-on-rails - rails 开发环境不重新加载更改 View

database - 如何将用户创建的符号数学存储在数据库中?

postgresql - Postgres - 更新和重构 JSON 类型列的属性

java - 将图像保存到 sqlite 然后应用程序崩溃

android - 如何存储自定义对象的数组列表?

ruby-on-rails - 如何为访问者向我的 Rails 应用程序添加页面缓存?