Question: Sorting in Rails: SQLite vs PostgreSQL


Sorting in Rails: SQLite vs PostgreSQL

Answers 1
Added at 2017-01-04 18:01

When I order by a column (id type INT) in Rails 5 with sqlite as the development db, it sorts as expected (1,2,3,4...) but the same thing on my production environment (PostgreSQL) results in unexpected behaviour (1, 101, 102,...2, 201,...) and so on.

If I format the order as per PostgreSQL (MyModel.order('id::integer DESC') then it works fine in PostgreSQL but no longer works in my development sqlite environment.

Am I overlooking something? I'm quite new to programming.

Answers to

Sorting in Rails: SQLite vs PostgreSQL

nr: #1 dodano: 2017-01-05 04:01

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

Source Show
◀ Wstecz