Note that there are some explanatory texts on larger screens.

plurals
  1. POLogs with arbitrary numbers of entries in PostgreSQL
    primarykey
    data
    text
    <p>I'm designing a db in PostgreSQL that primarily stores info about different people. I'd like to associate a log with each person, consisting of the date and a text entry. Logs can have arbitrary numbers of entries. Here's the ideas I've toyed with:</p> <ol> <li><p>What I think I want is a <code>log_table</code> like this:</p> <pre><code>person_id | row_num | row_date | row_text ----------------------------------------- 1 | 1 | 01/01/12 | Blah... 2 | 1 | 01/02/12 | Foo... 1 | 2 | 01/04/12 | Bar... </code></pre></li> </ol> <p>But I don't know how to get <code>row_num</code> to increment properly; it should default to one more than the largest current <code>row_num</code> for that person_id. In other words, the <code>row_num</code>s for a given <code>person_id</code> should be sequential.</p> <ol> <li><p>Or I can just have <code>row_num</code> increment regardless of <code>person_id</code> so that every log entry has a distinct row number. But it doesn't seem very satisfying to have <code>person_id</code> 1's log jump from row 1 to row 3, and this could also make errors hard to spot.</p></li> <li><p>My last idea is to include the log directly in the <code>person</code> table, by making a composite type <code>log_entry = (date, text)</code>. Then a column <code>log</code> in the <code>person</code> table can store an array:</p> <pre><code>person_id | name | log ---------------------- 1 | Bob | {(01/01/12, Blah...), (01/04/12, Bar...)} </code></pre></li> </ol> <p>But this seems cumbersome.</p> <p>So my questions are, a) which solution if any is good design; b) any way to solve the auto-incrementing problem for solution 1? If it matters, this is a small db for personal use; I want good structure but it's highly likely I'll be the only user. Thanks so much for any help!</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.
    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