Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If your values are only ever going to be numeric plus N/A, then you can do as Perception and Gavin Xiong suggested and store this as a NUMBER column in the DB. I'd make the column nullable and use DBNULL to represent N/A as Perception suggests, rather than using a magic value (even a "standard" one like -1). Neither of them addressed how to represent this in the Java code, but I think that null in Java is a more natural mapping to DBNULL in a database in most cases, so I'd represent this as an Integer (Object) rather than an int (primitive) with null == DBNULL == N/A, unless there's a reason to do otherwise.</p> <p>You yourself brought up the edge case of how to handle formulas (e.g. AVERAGE) for N/A values, and you'll need to define your desired behavior in those cases to get a final answer. Your decision of how to store these value will also make a difference to how complicated your formula queries have to be; if you store the value as -1 the way Gavin suggests, you're definitely going to have to write a query with a WHERE clause to exclude those rows from an average value (if that's your desired behavior), whereas you might get some of that for free if you make the column NULLABLE and store DBNULL as the value for N/A.</p> <p>One note: you should be pretty sure that you're not going to have any non-numeric values other than N/A before you map N/A to DBNULL. If you think there's a good chance there will be other non-numeric values in the future, I'd think seriously about storing this differently, because DBNULL is only ever going to let you represent one non-numeric value. If you have to go down that path, I'd store everything as VARCHARs in the DB, and then add code in either Java or SQL/JPA that parse the numeric strings into a number and runs your formula on them dynamically. (You could do it with multiple magic values like -1, -2, etc., but it will quickly get kludgy if you have more than a couple of them.)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload