Re: How do I create a drop down list?

Поиск
Список
Период
Сортировка
От Lew
Тема Re: How do I create a drop down list?
Дата
Msg-id jjul47$3nl$1@news.albasani.net
обсуждение исходный текст
Ответ на Re: How do I create a drop down list?  (Bartosz Dmytrak <bdmytrak@eranet.pl>)
Список pgsql-novice
On 03/15/2012 02:54 PM, Bartosz Dmytrak wrote:
> MrTeeth wrote:
>>     I'm new to PostgreSQL.
>>
>>     I was wondering, how do I make a column a drop down list.
>>
>>     So i've got a table called Student. There's a column in there called
>>     "student_type", which means whether the student is a part time student, full
>>     time student or is sandwich course student.
>>
>>     So I want to make "student_type" a drop down list with 3 choices: "part
>>     time" student, "full time" and "sandwich".
>>
>>     How do I do this?
>>
>>     (I'm using pgAdmin to create the databse, by the way.)
>
> I think You use MS Access before.
> It is not possible to create such drop down list using pgAdmin, but it is
> possible to limit acceptable values in field "student_type" in few different
> ways. Still this will not be a drop-down or combobox filed.
>
> eg:
> You can use table with dictionary and then use foreign key,
> You can use constraint to check inserted value
> You can use domain (field is in type of Your domain, and domain is based on
> proper constraint)
> You can use trigger (before insert or update)
> etc.

To put this a different way, Postgres is a database, not a user-interface
library. It doesn't have dropdown lists, text boxes, labels and all that. It
is not directly usable by a human that way.

What PG can do is provide a stable source for data used by such widgets. Each
widget library has its own rules for how to bind (that is, connect) to a data
source. Some let you directly connect the visual component, in this case the
dropdown widget, to a database, or better, a database cursor.

With Postgres you can create a cursor, which is an in-memory window into the
result of a SELECT query of some kind, that your widget or favorite
programming language binds to. In your example, the cursor or widget binding
would be to the result of a "SELECT student_type FROM student_type" query.

As an aside, the values for "student_type" should not be stored only in
"student". You should have a normalized table structure, which here would give
you a "student_type" table that holds the three choices, one per row. (There
are other ways to do this.) The values you specified would be the primary key
column. (Alternatively you'd have those values in a UNIQUE column with a
surrogate key as the primary key, but that's probably overkill for a simple
lookup table.) The "student.student_type" column would then be a foreign key
into the "student_type.student_type" column.

--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

В списке pgsql-novice по дате отправления:

Предыдущее
От: MrTeeth
Дата:
Сообщение: Re: How do I create a drop down list?
Следующее
От:
Дата:
Сообщение: Re: repeatet summary querys per month over 5 years