Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can store an array in a single string field, if you somehow genereate a string representation of it, e.g. sing the <code>pickle</code> module. Then, when you read the line, you can unpickle it. Pickle converts many different complex objects (but not all) into a string, that the object can be restored of. But: that is most likely not what you want to do (you wont be able to do anything with the data in the tabel, except selecting the lines and then unpickle the array. You wont be able to search.</p> <p>If you want to have anything of varying length (or fixed length, but many instances of similiar things), you would not want to put that in a column or multiple columns. Thing vertically, not horizontally there, meaning: don't thing about columns, think about rows. For storing a vector with any amount of components, a table is a good tool.</p> <p>It is a little difficult to explain from the little detail you give, but you should think about creating a second table and putting all the names there for every row of your first table. You'd need some key in your first table, that you can use for your second table, too:</p> <pre><code>c.execute("CREATE TABLE first_table(int id, varchar(255) text, additional fields)") c.execute("CREATE TABLE names_table(int id, int num, varchar(255) name)") </code></pre> <p>With this you can still store whatever information you have except the names in <code>first_table</code> and store the array of names in <code>names_table</code>, just use the same <code>id</code> as in <code>first_table</code> and <code>num</code> to store the index positions inside the array. You can then later get back the array by doing someting like</p> <pre><code>SELECT name FROM names_table WHERE id=? ORDER BY num </code></pre> <p>to read the array of names for any of your rows in <code>first_table</code>.</p> <p>That's a pretty normal way to store arrays in a DB.</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. 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