X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6B6AF9DC81F for ; Tue, 14 Feb 2006 18:41:24 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 87495-03 for ; Tue, 14 Feb 2006 18:41:26 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from rwcrmhc12.comcast.net (rwcrmhc12.comcast.net [216.148.227.152]) by postgresql.org (Postfix) with ESMTP id 4FF319DC804 for ; Tue, 14 Feb 2006 18:41:22 -0400 (AST) Received: from [10.0.1.5] (c-24-20-199-254.hsd1.or.comcast.net[24.20.199.254]) by comcast.net (rwcrmhc12) with SMTP id <20060214224124m1200qnl4pe>; Tue, 14 Feb 2006 22:41:24 +0000 Subject: Re: create table and data types From: Ken Hill Reply-To: ken@scottshill.com To: Maciej Piekielniak Cc: pgsql-sql@postgresql.org In-Reply-To: <1621743066.20060214230317@isb.com.pl> References: <1827225102.20060214221218@isb.com.pl> <1139952634.3083.72.camel@localhost.localdomain> <1621743066.20060214230317@isb.com.pl> Content-Type: multipart/alternative; boundary="=-wIx1BTKSPRiLZzoUCoY3" Organization: Scotts Hill Associates, Inc. Date: Tue, 14 Feb 2006 14:42:02 -0800 Message-Id: <1139956922.3083.79.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.085 required=5 tests=[AWL=0.084, HTML_MESSAGE=0.001] X-Spam-Score: 0.085 X-Spam-Level: X-Archive-Number: 200602/160 X-Sequence-Number: 24170 --=-wIx1BTKSPRiLZzoUCoY3 Content-Type: text/plain Content-Transfer-Encoding: 7bit On Tue, 2006-02-14 at 23:03 +0100, Maciej Piekielniak wrote: > Hello Ken, > > Tuesday, February 14, 2006, 10:30:34 PM, you wrote: > KH> On Tue, 2006-02-14 at 22:12 +0100, Maciej Piekielniak wrote: > > >> Hello pgsql-sql, > >> > >> Is anybody know how create field in a new table with data type accuiring from a field in other table? > >> For example: > >> > >> create table new_table > >> ( > >> name other_table.name%TYPE > >> ); > >> > > KH> Have you tried inheritance from one table to the new table? > > KH> CREATE TABLE new_table (new_column) > KH> INHERITS (old_table) > > KH> All columns in 'old_table' will be inclueded in 'new_table' plus the > KH> column 'new_column'. > > yes, but i don't need all colums, i need only the same data type for only > some fields. > > for example > create table new table > ( > name other_table.name%TYPE, > mynewfield VARCHAR(100), > mynewfield2 VARCHAR(100) > ); > Have you tried restructuring the table with CREATE TABLE AS...? Try this: CREATE TABLE new_table (id, mynewfield, mynewfield2) AS SELECT id FROM old_table); This should create a new table ('new_table') with the data-type for 'old_table' for the id column. --=-wIx1BTKSPRiLZzoUCoY3 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit On Tue, 2006-02-14 at 23:03 +0100, Maciej Piekielniak wrote:
Hello Ken,

Tuesday, February 14, 2006, 10:30:34 PM, you wrote:
KH> On Tue, 2006-02-14 at 22:12 +0100, Maciej Piekielniak wrote:

>> Hello pgsql-sql,
>> 
>>   Is anybody know how create field in a new table with data type accuiring from a field in other table?
>>   For example:
>> 
>> create table new_table
>> ( 
>>  name other_table.name%TYPE
>> ); 
>> 

KH> Have you tried inheritance from one table to the new table?

KH> CREATE TABLE new_table (new_column)
KH>      INHERITS (old_table)

KH> All columns in 'old_table' will be inclueded in 'new_table' plus the
KH> column 'new_column'.

yes, but i don't need all colums, i need only the same data type for only
some fields.

for example
create table new table
(
 name other_table.name%TYPE,
 mynewfield VARCHAR(100),
 mynewfield2 VARCHAR(100)
);

Have you tried restructuring the table with CREATE TABLE AS...? Try this:

CREATE TABLE new_table
     (id, mynewfield, mynewfield2)
     AS SELECT id FROM old_table);

This should create a new table ('new_table') with the data-type for 'old_table' for the id column. --=-wIx1BTKSPRiLZzoUCoY3--