Re: inherits clause for CREATE TYPE? - - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: inherits clause for CREATE TYPE? -
Date
Msg-id CAFj8pRBQY6Ohk0B_NWFfX=a_qNhAMBwSnSk29CXsQ2-HzJv6jQ@mail.gmail.com
Whole thread Raw
In response to Re: inherits clause for CREATE TYPE? -  (Merlin Moncure <mmoncure@gmail.com>)
List pgsql-hackers


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

pgsql-hackers by date:

Previous
From: Simon Riggs
Date:
Subject: Re: Read Uncommitted
Next
From: Amit Kapila
Date:
Subject: Re: [HACKERS] Block level parallel vacuum