Note that there are some explanatory texts on larger screens.

plurals
  1. POPostgresql - human-readable aliases for numerical primary keys
    primarykey
    data
    text
    <p>Like many databases, I have a table of people with a serial-generated numerical primary key, since names are not unique:</p> <pre><code>ID NAME STUFF --------------- 101 Bob 20 102 Bob 30 </code></pre> <p>And several other tables reference these IDs as a foreign key:</p> <pre><code>ORDER PERSON NOTE ------------------- 1 02 Blah 2 01 Foo </code></pre> <p>(Can't use name instead of ID as FK since FKs must reference a column with a unique constraint). Since my data entry is manual, using a GUI (right now pgAdmin or LibreOffice on a Mac) it would be much easier to see a person's name instead of numerical ID when working on the order table. I've thought of a number of solutions to this seemingly simple problem and none seem good:</p> <p>A) Views - not editable. I know <a href="http://www.postgresql.org/docs/9.1/static/plpgsql-trigger.html" rel="nofollow">how to make views editable with triggers</a> but AFAIK no GUI editor can use this to allow editable views.</p> <p>B) Add a name column to Order table, then use triggers to keep everything in sync - it's tempting, but then I have duplicate data, and a headache when my table structure evolves. Somewhat better if the Order name column is enforced read-only with triggers, but still many pitfalls.</p> <p>C) What I REALLY want is some way to toggle the GUI editor between displaying the person ID and the corresponding name, in whatever arbitrary tables they appear in, without compromising the underlying data integrity.</p> <p>Hope this is clear; can provide more details if needed. Thanks for any help!</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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