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

  • Home
  • SEARCH
  • 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 756863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:17:41+00:00 2026-05-14T15:17:41+00:00

Intro I am trying to decide how best to set up my database schema

  • 0

Intro

I am trying to decide how best to set up my database schema for a (Rails) model. I have a model related to money which indicates whether the value is an income (positive cash value) or an expense (negative cash value).

I would like separate column(s) to indicate whether it is an income or an expense, rather than relying on whether the value stored is positive or negative.


Question:

How would you store these values, and why?

  • Have a single column, say Income,
    and store 1 if it’s an income, 0
    if it’s an expense, null if not
    known.
  • Have two columns, Income and
    Expense, setting their values to 1 or 0 as
    appropriate.
  • Something else?

I figure the question is similar to storing a person’s gender in a database (ignoring aliens/transgender/etc) hence my title.


My thoughts so far

  • Lookup might be easier with a single column, but there is a risk of mistaking 0 (false, expense) for null (unknown).
  • Having seperate columns might be more difficult to maintain (what happens if we end up with a 1 in both columns?

Maybe it’s not that big a deal which way I go, but it would be great to have any concerns/thoughts raised before I get too far down the line and have to change my code-base because I missed something that should have been obvious!

Thanks,
Philip

  • 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-14T15:17:41+00:00Added an answer on May 14, 2026 at 3:17 pm

    How would you store these values, and why?

    I would store them as a single column. Despite your desire to separate the data into multiple columns, anyone who understands accounting or bookkeeping will know that the dollar value of a transaction is one thing, not two separate things based on whether it’s income or expense (or asset, liablity, equity and so forth).

    As someone who’s actually written fully balanced double-entry accounting applications and less formal budgeting applications, I suggest you rethink your decision. It will make future work on this endeavour a lot easier.

    I’m sorry, that’s probably not what you want to hear and may well result in ngative rep for me but I can’t, in all honesty, let this go without telling you what a mistake it will be.

    Your “thoughts so far” are an indication of the problems already appearing.

    1/ “Having seperate columns might be more difficult to maintain (what happens if we end up with a 1 in both columns?” – well, this shouldn’t happen. Data is supposed to be internally consistent to the data model. You would be best advised preventing it with an insert/update trigger or, say, a single column that didn’t allow it to happen 🙂

    2/ “Lookup might be easier with a single column, but there is a risk of mistaking 0 (false, expense) for null (unknown).” – no mistake possible if the sign is stored with the magnitude of the value. And the whole idea of not knowing whether an item is expense or income is abhorrent to accountants. That knowledge exists when the transaction is created, it’s not something that is nebulous until some point after a transaction happens.

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

Sidebar

Related Questions

I’m trying to decide the best way to load data into my app, it’s
I'm trying to decide on the best way to load in some configuration settings.
Intro : I'm trying to migrate our Trac SQLite to a PostgreSQL backend, to
I was trying to code along with the PDC2008 Intro to F# video .
Im using a Core Data model for my iPhone app. I have been looking
Ok so I am trying to import a csv which I need to insert
There doesn't seem to be any tried and true set of best practices to
I have an existing Rails 2.3.10 app that I'm considering upgrading to Ruby 1.9.2
I am digging into LINQ--trying to understand basic models (it seems pretty cool to
I'm running into a problem trying to anchor a textbox to a form on

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.