pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ken Hill <ken@scottshill.com>
To: Maciej Piekielniak <piechcio@isb.com.pl>
Cc: pgsql-sql@postgresql.org
Subject: Re: create table and data types
Date: Tue, 14 Feb 2006 14:42:02 -0800
Message-ID: <1139956922.3083.79.camel@localhost.localdomain> (raw)
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>

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.

view thread (6+ messages)  latest in thread

Message-ID: <1139956922.3083.79.camel@localhost.localdomain>
Permalink:  ../1139956922.3083.79.camel@localhost.localdomain/
Also on:    postgresql.org/message-id/1139956922.3083.79.camel@localhost.localdomain

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ken@scottshill.com, piechcio@isb.com.pl
  Subject: Re: create table and data types
  In-Reply-To: <1139956922.3083.79.camel@localhost.localdomain>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox