Foreign key constraint accepted even when not same data type - Mailing list pgsql-general

From Jean-Christian Imbeault
Subject Foreign key constraint accepted even when not same data type
Date
Msg-id 3F6EF483.8040807@mega-bucks.co.jp
Whole thread Raw
Responses Re: Foreign key constraint accepted even when not same  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
Re: Foreign key constraint accepted even when not same  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
List 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




pgsql-general by date:

Previous
From: Richard Welty
Date:
Subject: Re: PostgreSQL versus MySQL
Next
From: Jean-Christian Imbeault
Date:
Subject: Foreign key constraint accepted even when not same data type