how to create a new composite type using already existing composite types

From: Iain Barnett <iainspeed(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: how to create a new composite type using already existing composite types
Date: 2010-02-10 03:46:45
Message-ID: 19EE1475-4329-464C-9781-00AE8C4306AB@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

Is there a way to create a new composite type using already existing composite type?

For example,

CREATE TABLE inventory_item (
name text,
supplier_id integer REFERENCES suppliers,
price numeric CHECK (price > 0)
);

produces the following type automatically
CREATE TYPE inventory_item AS (
name text,
supplier_id integer,
price numeric
);

but I'd also like to have a type with an extra column for certain functions

CREATE TYPE inventory_item2 AS (
name text,
supplier_id integer,
price numeric,
size integer
);

but it would be handy if I could reuse inventory_item instead of having to retype the whole lot. I can't work out or find the right syntax, can anyone show me how? Any help would be much appreciated.

Regards
Iain

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jayadevan M 2010-02-10 04:09:02 PostgreSQL - case studies
Previous Message BillR 2010-02-10 03:31:07 Re: R: One column to multiple columns based on constraints?