Automatic typing of foreign keys when creating tables

From: "Scott Goodwin" <scott(at)scottg(dot)net>
To: pgsql-admin(at)postgresql(dot)org
Subject: Automatic typing of foreign keys when creating tables
Date: 2001-01-02 15:35:21
Message-ID: 92ssgf$1fql$1@news.tht.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

This is really a suggestion rather than a question:

I've noticed that Oracle allows you to not declare the type of column if the
column is a foreign key and the primary key has already been declared in
another table.

Though not a critical feature, I think it would be great if PostgreSQL could
do this; it would save time during development as you wouldn't have to find
and change all of the foreign key type declarations to match the primary key
type every time you decided to change the primary key type.

The first piece shows the PostgreSQL way, where object_type is declared as
an integer. The second shows how object_type is not declared as an integer
or any other type.

===================== PostgreSQL

create table itk_object_types (
object_type integer primary key
);

create table itk_objects (
object_id integer not null
constraint itk_objects_pk primary key,
object_type integer not null
constraint itk_objects_object_type_fk
references itk_object_types(object_type)
);

===================== Oracle

create table itk_object_types (
object_type integer primary key
);

create table itk_objects (
object_id integer not null
constraint itk_objects_pk primary key,
object_type not null
constraint itk_objects_object_type_fk
references itk_object_types(object_type)

);

/s.

Browse pgsql-admin by date

  From Date Subject
Next Message Tom Lane 2001-01-02 16:44:45 Re: pg_dump/psql < db.out issue
Previous Message Anthony E . Greene 2001-01-02 14:30:25 Re: pg_dump/psql < db.out issue