r/programming • • Sep 24 '20

PostgreSQL 13 Released!

https://www.postgresql.org/about/news/2077/
1.3k Upvotes

236 comments sorted by

View all comments

Show parent comments

2

u/ShapeOfMatter Sep 25 '20

Sure. Part of what's so egregious is that it's not documented better, although it would be a pretty baffling and bad design even if it were well documented.

Here's the documentation page for table declarations. Right at the top is the syntax description like you'd expect. If you follow the definitions create_definition -> column_definition -> reference_definition, you'll see that you can declare a foreign key in MySQL the same way you're probably accustomed to from other languages:

CREATE TABLE table_x
    y_values INT REFERENCES table_y (y_values);

And if you run that, the engine will say "OK, that worked and your table exists. But there won't actually be a foreign key!.

If you read almost half way down that page, there's a blue "Important" box, the last paragraph of which mentions that "MySQL parses but ignores inline REFERENCES specifications". It's also mentioned on this other errata page. But if you didn't already know there was a problem, you'd never find these warnings.

1

u/GhostNULL Sep 25 '20

Ooh okay, what I understood from your previous comment was that it ignored foreign keys when declared in the CREATE TABLE statement in general, not just when you put REFERENCES table (x) on the column. Thanks for clarifying that!