Skip site navigation (1) Skip section navigation (2)

foreign key data type dereferencing

From: Murat Tasan <murat(dot)tasan(at)cwru(dot)edu>
To: pgsql-novice(at)postgresql(dot)org
Subject: foreign key data type dereferencing
Date: 2006-03-23 20:51:17
Message-ID: 788CEACA-1046-4682-9464-08C86E888A42@cwru.edu (view raw or flat)
Thread:
Lists: pgsql-novice
Hi all, I have a quick question...

In function definitions one can dereference the type of some  
relation's column using the %TYPE syntax.  This is a very useful  
feature that helps prevent type mismatch problems in databases that  
are frequently changing (for example in a scientific environment  
where tables are being added often, and the re-use of an already  
defined function is then simple).

It would also be useful to have the same functionality in the CREATE  
TABLE statement, in particular when defining a FOREIGN KEY  
constraint.  For example, something along these lines:

CREATE TABLE foo (attribute_1 other_table.attribute_pk%TYPE  
REFERENCES other_table.attribute_pk);

or the even simpler:

CREATE TABLE foo (attribute_1 REFERENCES other_table.attribute_pk);

However, this doesn't seem possible.  Now, under the assumption that  
many people have encountered this in the past, I'm curious about the  
different solutions/workarounds most have employed successfully.

Thanks for any insight on this,

Murat

Responses

pgsql-novice by date

Next:From: Sean DavisDate: 2006-03-23 21:24:09
Subject: Re: foreign key data type dereferencing
Previous:From: Guido BarosioDate: 2006-03-23 18:18:24
Subject: Re: Problems using PostgreSQL command line tools

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group