Re: User defined types

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: User defined types
Дата
Msg-id 1114.1101407382@sss.pgh.pa.us
обсуждение исходный текст
Ответ на User defined types  (Reza Shanbehbazari Mirzaei <mirzaei@stud.ntnu.no>)
Список pgsql-sql
Reza Shanbehbazari Mirzaei <mirzaei@stud.ntnu.no> writes:
>   I have a user define type called VALID_TIME. It is declared as follows:

>   CREATE TYPE VALID_TIME AS (t_s TIMESTAMP, t_e TIMESTAMP);

>   Once I have used this in a table declaration, is it possible to extract
> parts of it, for example to only read t_s or t_e? If so, how do I do this?

8.0 supports using composite types as table columns, but prior versions
don't really.  In 8.0 you'd do something like
create table myt (vt valid_time);
select (vt).t_s from myt;
orselect (myt.vt).t_s from myt;

The parentheses are essential --- without them, you'd have for instance
select vt.t_s from myt;

which looks like a reference to field t_s of table vt, not what you
want.

You can hack around the problem in earlier versions by creating helper
functions, eg
select get_t_s(vt) from myt;

but it's ugly enough to make one wonder why bother with a composite type.
        regards, tom lane


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

Предыдущее
От: Dave Steinberg
Дата:
Сообщение: PG7.4.5: query not using index on date column
Следующее
От: Andrew M
Дата:
Сообщение: HowTo change encoding type....