Note that there are some explanatory texts on larger screens.

plurals
  1. POMixed content (float || unicode) for database column
    primarykey
    data
    text
    <p>For sake of simplicity let's say I have a questionare.</p> <p>Each answer gains a score.</p> <p>Some questions are <em>qualitative</em> so user must choose between one of the text answers.</p> <p><strong>Q: what's your fav pet?</strong></p> <ol> <li>cat [1 point]</li> <li>dog [2 points]</li> <li>caiman [3 points]</li> </ol> <p>Answering <em>dog</em> I get 2 points.</p> <p>Some questions are <em>quantitative</em> so user inputs a number and gets scoring with linear interpolation:</p> <p><strong>How much beer liters do you drink in a day?</strong></p> <ol> <li>0 [0 points]</li> <li>1 [1 point]</li> <li>3 [5 points]</li> </ol> <p>If I answer <em>2 liters</em> I get <strong>3 points</strong>.</p> <p>Now I use sqlalchemy and have a table with an answer each row:</p> <pre><code>questions id PK name String quantitative Bool answers id Integer PK id_question Integer FK value String </code></pre> <p>and cast <code>answers.value</code> to float each time I have to deal with it as a number for interpolation and so on.</p> <ol> <li><p>I could change column name <code>value</code> to <code>_value</code> and make getter and setter functions for <code>answer.value</code> that casts each time to float <code>answer._value</code> if question is numeric (<code>answer.question.quantitative</code> is <code>True</code>)</p></li> <li><p>I could have separate columns in answer for textual and numeric values (like <code>value</code> and <code>text</code>, I will have no millions of records anyway)</p></li> <li><p>Or...</p></li> </ol> <p>What is supposed to be more efficient and easy to use?</p> <p>Please consider SQLAlchemy magic that takes care of a lot of the dirty work, I'd like to keep it that simple.</p> <hr> <p><em>Edit</em>:</p> <p>Since <em>beer example</em> could be misleading I integrate with another:</p> <p><strong>Q: how many money do you give in charity in USD?</strong></p> <ol> <li>0 [0 point]</li> <li>10 [1 point]</li> <li>100 [2 points]</li> </ol> <p>Like for <em>pets &amp; beer question</em> I have answer values <code>"0"</code>, <code>"10"</code>, <code>"100"</code> stored in database as strings in <code>answers.value</code> column so to interpolate values to get score for answer <code>50</code> I have all the time to cast <code>answers.value</code> to float.</p> <p>Here's where I have mixed content type in the same db column.</p>
    singulars
    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. 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