gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 12:25:26 25 4
gpt4 key购买 nike

当我在 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/

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