Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6054581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:10:08+00:00 2026-05-23T08:10:08+00:00

I have a Transaction model in a Rails 3.1.0.rc4 app with a decimal attribute

  • 0

I have a Transaction model in a Rails 3.1.0.rc4 app with a decimal attribute amount. I have records where the amount attribute is more than 0 as well as records where the amount attribute is less than 0. I want to get all the records where the amount is more than 0. I tried Transaction.where('amount > 0') and Transaction.where('amount > 0.0') but in both cases, all the records are returned, including the ones with a negative amount. When I run Transaction.where('amount < 0') or Transaction.where('amount < 0.0') no records are returned.

Is it possible to do these types of queries on decimal attributes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:10:09+00:00Added an answer on May 23, 2026 at 8:10 am

    The problem is with SQLite and your migrations – if you open up your SQLite database and run SELECT typeof(amount) FROM transactions LIMIT 1 you’ll see that Rails is creating your decimal field as a BLOB type instead of the decimal REAL type.

    I’m not sure if this is a Rails bug or not, but for the time being you can get around it by casting the amount in your where clause:

    Transaction.where("CAST(amount AS REAL) > 0")
    

    You can also get around this by using straight SQL in your migration with the execute method to create amount as a REAL field to begin with (see http://api.rubyonrails.org/classes/ActiveRecord/Migration.html).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Rails 2.3.11 app which has two key Models: Activity Transaction Live
I have a transaction log file in CSV format that I want use to
Consider that I have a transaction: BEGIN TRANSACTION DECLARE MONEY @amount SELECT Amount AS
Well i have a complex form view model like this : public class TransactionFormViewModel
The particular case I have is like this: I have a Transaction model, with
I have a model class Transaction(models.Model): sender = models.ForeignKey(MyBankAccount, unique=False, related_name=transactions_sent) receiver = models.ForeignKey(RecipientBankAccount,
In my rails app I have 2 models: post and post_translations. class PostTranslation <
I have a weird bug that just popped up with my rails app that
In my data model I have a fairly common division between my objects/tables/data: Transactional
I have a transaction table like so id , name , code , flag

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.