Automatic typing of foreign keys when creating tables - Mailing list pgsql-admin

From Scott Goodwin
Subject Automatic typing of foreign keys when creating tables
Date
Msg-id 92ssgf$1fql$1@news.tht.net
Whole thread Raw
List 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.



pgsql-admin by date:

Previous
From: Tom Lane
Date:
Subject: Re: pg_dump/psql < db.out issue
Next
From: Michael Davis
Date:
Subject: RE: pg_dump/psql < db.out issue