Dynamic Column Value Insert

From: Jon Forsyth <jon4syth(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Dynamic Column Value Insert
Date: 2016-12-20 18:16:09
Message-ID: CACv13prTLi_7UgqUnWnAfVqfU0kkaju1OWYRX_eR6jZ8g6UznA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hello all,

I have a database that stores tests for students at a 2nd language school.
I designed it such that there is a parent Question table that can relate to
any ONE of a few QuestionType tables--Vocabulary, Writing, Speaking,
etc--in a one to one relationship. I'd like to add a column 'type' to the
parent Question table that contains a string of the type of question it is
related to where the string is take from a fixed list of possible
strings--like an Enum type. Furthermore, having this type column
automatically populated at the time it's primary key is added to a child
table as a foreign key and based on which child table that is, would be
fantastic. My goal is to make it easier for developers to get the type of
question, rather than having to query all possibly related child tables
(only one of them will be related) , so maybe this isn't the best solution
since it sort of adds redundancy. I'm open to other options/advice. Note:
the query will be starting from the question (parent table) rather than the
child necessarily so, otherwise it would be solved.

Thanks!

Jon

Browse pgsql-novice by date

  From Date Subject
Next Message Jeffrey A Trimble 2017-01-04 15:52:37 server log error on startup
Previous Message Tom Lane 2016-12-13 05:21:44 Re: Boolean column in multicolumn index