From: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
---|---|
To: | gmb <gmbouwer(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: CREATE TABLE & composite type |
Date: | 2017-06-28 13:37:24 |
Message-ID: | f43d4ed6-e9d7-45fb-affa-823aa61565b0@aklaver.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 06/28/2017 06:27 AM, gmb wrote:
> Hi Referencing https://www.postgresql.org/docs/9.6/static/rowtypes.html
> Taking a chance here.... Is there a short-hand way in which I can create
> a table with the same structure as a user defined composite type ? E.g.
> CREATE TYPE inventory_item AS ( name text, supplier_id integer, price
> numeric ); CREATE TABLE inventory_item_table ( like type inventory_item
> ); We're using composite types rather extensively as the return
> structure of functions: CREATE FUNCTION some_func() RETURNS SETOF
> inventory_item ....; Of course I can: CREATE TABLE inventory_item_table
> AS ( SELECT some_func( ) );
CREATE TABLE inventory_item_table AS ( SELECT some_func( ) limit 0);
But , in some cases , where the function
> returns a large number of records I want to create the table beforehand
> in order to add indexes: CREATE TABLE inventory_item_table ( like type
> inventory_item ); CREATE INDEX idx ON inventory_item_table ( id );
> INSERT INTO inventory_item_table SELECT some_func(); Will appreciate any
> input. Regards gmbouwer
> ------------------------------------------------------------------------
> View this message in context: CREATE TABLE & composite type
> <http://www.postgresql-archive.org/CREATE-TABLE-composite-type-tp5969032.html>
> Sent from the PostgreSQL - general mailing list archive
> <http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html> at
> Nabble.com.
--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | gmb | 2017-06-28 13:51:58 | Re: CREATE TABLE & composite type |
Previous Message | Adrian Klaver | 2017-06-28 13:31:11 | Re: Accessing DB2 tables from postgresql |