Composite types or composite keys?

Поиск
Список
Период
Сортировка
От Tony Theodore
Тема Composite types or composite keys?
Дата
Msg-id 6D46FD23-2011-4E52-BD54-09FC54A0C117@gmail.com
обсуждение исходный текст
Ответы Re: Composite types or composite keys?  (Merlin Moncure <mmoncure@gmail.com>)
Список pgsql-general
Hi,

I was reading about composite types and wondering if I should use them instead of composite keys. I currently have
tableslike this: 

create table products (
    source_system text,
    product_id text,
    description text,
    ...
    primary key (source_system, product_id)
);
create table inventory (
    source_system text,
    product_id text,
    qty int,
    ...
    foreign key (source_system, product_id) references products
);


and it means having to add the “source_system" column to many queries. Would something like:

create type product as (
    source_system text,
    product_id text
);
create table products (
    product product,
    description text,
    ...
    primary key(product)
);
create table inventory (
    product product,
    qty numeric,
    ...
    foreign key (product) references products
);

be a correct use of composite types? I rarely need to see the columns separately, so having to write
“(product).product_id”won’t happen much in practice. 

Thanks,

Tony



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

Предыдущее
От: Philippe Girolami
Дата:
Сообщение: Re: Push predicate down in view containing window function
Следующее
От: Jayadevan M
Дата:
Сообщение: Postgres Server backend process