Обсуждение: References not being checked while creating tables?

Поиск
Список
Период
Сортировка

References not being checked while creating tables?

От
Bas van der Linden
Дата:
Hi all,

I've just started learning SQL, wich is great fun. However, there's something
I don't understand, wich has to do with references.


Take this example:

CREATE TABLE test (
id        serial
);

CREATE TABLE test2 (
another_id    REFERENCES test(id)
);

This doesn't work, because I didn't tell the database what data type to use for
another_id. However, my point is that it _is_ able to deduct what data type
to use for another_id, as it is a reference to something I have defined.


And something related:

CREATE TABLE test (
id        serial
);

CREATE TABLE test2 (
another_id    text REFERENCES test(id)
);

This is accepted by the database, however, it obviously is of no use whatsoever
as the data types are incompatible.

What am I missing or overseeing here?
(Or to refrase the question: Why is it not checking this and who do I have to
suck up to in order to get this implemented? :)


Thanks in advance!

Bas van der Linden


--
B.J.J. van der Linden            Amaze Internet Services V.O.F.
Brouwersgracht 132               Tel:   020-4688336
1013 HA Amsterdam                Fax:   020-4688337
Email: bas@amaze.nl              Web:   http://www.amaze.nl/

Re: References not being checked while creating tables?

От
Tom Lane
Дата:
Bas van der Linden <bas@mike.amaze.nl> writes:
> CREATE TABLE test (
> id        serial
> );

> CREATE TABLE test2 (
> another_id    text REFERENCES test(id)
> );

> This is accepted by the database, however, it obviously is of no use
> whatsoever as the data types are incompatible.

Yes, the type mismatch should be detected sooner.  I thought we had
fixed this for 7.1, but I see it still doesn't notice the problem
until runtime.  Oh well, another TODO item for 7.2 ...

            regards, tom lane