Обсуждение: inherits clause for CREATE TYPE? -

Поиск
Список
Период
Сортировка

inherits clause for CREATE TYPE? -

От
Pavel Stehule
Дата:
Hi

I had a talk with one boy about development in plpgsql. He uses table's functions. More times he uses returns types based on some table type + few attributes. Now he use a ugly hack - he create a view on table plus some columns - and then he use the view related type as table function result type. For similar uses cases there can be interesting to have a possibility to create types by extending other types. Probably almost all functionality is inside now - so it should not be hard work.

My idea is implement inherits clause for CREATE TYPE command.

Some like

CREATE TYPE fx_rt (xx int) INHERITS(pg_class);

What do you think about this idea?

Regards

Pavel

Re: inherits clause for CREATE TYPE? -

От
Tom Lane
Дата:
Pavel Stehule <pavel.stehule@gmail.com> writes:
> My idea is implement inherits clause for CREATE TYPE command.

-1.  We have enough problems dealing with alterations of inherited
rowtypes already.  As long as inheritance is restricted to tables,
we can use table locking to help prevent problems --- but there's
no provision for locking free-standing types.  And introducing
locking on types would cost way more than this seems likely to be
worth.

            regards, tom lane



Re: inherits clause for CREATE TYPE? -

От
Merlin Moncure
Дата:
On Wed, Dec 18, 2019 at 12:38 PM Pavel Stehule <pavel.stehule@gmail.com> wrote:
>
> Hi
>
> I had a talk with one boy about development in plpgsql. He uses table's functions. More times he uses returns types
basedon some table type + few attributes. Now he use a ugly hack - he create a view on table plus some columns - and
thenhe use the view related type as table function result type. For similar uses cases there can be interesting to have
apossibility to create types by extending other types. Probably almost all functionality is inside now - so it should
notbe hard work. 
>
> My idea is implement inherits clause for CREATE TYPE command.
>
> Some like
>
> CREATE TYPE fx_rt (xx int) INHERITS(pg_class);
>
> What do you think about this idea?

How about using composition style approaches?

create type base as (...)

create type extended as  (b base, ...)

create function foo() returns extended as ...

merlin



Re: inherits clause for CREATE TYPE? -

От
Osahon Oduware
Дата:
THE TRUTH CANNOT BE HIDDEN
**Explosion in my car.....

On Wed, 18 Dec 2019, 19:38 Pavel Stehule, <pavel.stehule@gmail.com> wrote:
Hi

I had a talk with one boy about development in plpgsql. He uses table's functions. More times he uses returns types based on some table type + few attributes. Now he use a ugly hack - he create a view on table plus some columns - and then he use the view related type as table function result type. For similar uses cases there can be interesting to have a possibility to create types by extending other types. Probably almost all functionality is inside now - so it should not be hard work.

My idea is implement inherits clause for CREATE TYPE command.

Some like

CREATE TYPE fx_rt (xx int) INHERITS(pg_class);

What do you think about this idea?

Regards

Pavel

Re: inherits clause for CREATE TYPE? -

От
Osahon Oduware
Дата:
THE TRUTH CANNOT BE HIDDEN
**Explosion in my car.....

On Wed, 18 Dec 2019, 20:06 Tom Lane, <tgl@sss.pgh.pa.us> wrote:
Pavel Stehule <pavel.stehule@gmail.com> writes:
> My idea is implement inherits clause for CREATE TYPE command.

-1.  We have enough problems dealing with alterations of inherited
rowtypes already.  As long as inheritance is restricted to tables,
we can use table locking to help prevent problems --- but there's
no provision for locking free-standing types.  And introducing
locking on types would cost way more than this seems likely to be
worth.

                        regards, tom lane


Re: inherits clause for CREATE TYPE? -

От
Pavel Stehule
Дата:


st 18. 12. 2019 v 21:12 odesílatel Merlin Moncure <mmoncure@gmail.com> napsal:
On Wed, Dec 18, 2019 at 12:38 PM Pavel Stehule <pavel.stehule@gmail.com> wrote:
>
> Hi
>
> I had a talk with one boy about development in plpgsql. He uses table's functions. More times he uses returns types based on some table type + few attributes. Now he use a ugly hack - he create a view on table plus some columns - and then he use the view related type as table function result type. For similar uses cases there can be interesting to have a possibility to create types by extending other types. Probably almost all functionality is inside now - so it should not be hard work.
>
> My idea is implement inherits clause for CREATE TYPE command.
>
> Some like
>
> CREATE TYPE fx_rt (xx int) INHERITS(pg_class);
>
> What do you think about this idea?

How about using composition style approaches?

create type base as (...)

create type extended as  (b base, ...)

create function foo() returns extended as ...

It is a possibility, but it is not practical, because base type will be nested, it is hard to access to nested fields ..

Currently I can do

CREATE TABLE base (...); -- instead CREATE TYPE
CREATE TABLE extended (...) -- INHERITS (base)

CREATE FUNCTION foo() RETURNS SETOF extended AS ..

This is working perfect - just disadvantage is garbage table "extended"



merlin