Foreign key constraint accepted even when not same data type

From: Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp>
To: postgresql <pgsql-general(at)postgresql(dot)org>
Subject: Foreign key constraint accepted even when not same data type
Date: 2003-09-22 13:09:23
Message-ID: 3F6EF483.8040807@mega-bucks.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Is it right for postgres to accept a foreign key constraint when the
type of the field is not the same as that of the foreign key?

For example:

# Create table a (id int primary key);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'a_pkey'
for table 'a'
CREATE TABLE
# Create table b (id2 text references a(id));

NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY
check(s)
CREATE TABLE

# \d a
Table "public.a"
Column | Type | Modifiers
--------+---------+-----------
id | integer | not null
Indexes: a_pkey primary key btree (id)

# \d b
Table "public.b"
Column | Type | Modifiers
--------+------+-----------
id2 | text |
Foreign Key constraints: $1 FOREIGN KEY (id2) REFERENCES a(id) ON UPDATE
NO ACTION ON DELETE NO ACTION

Jean-Christian Imbeault

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Robert Treat 2003-09-22 14:05:37 Re: OT: HEADS-UP: viral storm out there
Previous Message Rory Campbell-Lange 2003-09-22 12:42:18 How to find LIMIT in SQL standard