Debugging PostgreSQL More Easily
cybertec-postgresql.com
cybertec-postgresql.com
Table inheritance goes back to the 90's or something when Object databases were thought to be the 'next big thing'. It's not actively developed and has a lot of sharp edges and you shouldn't use it.
If you really want something like this, then I would use UUID primary keys, then make a view that UNION ALLs. like this:
CREATE VIEW id_to_table AS
SELECT id, 'products' FROM products
UNION ALL
SELECT id, 'users' FROM users
... and so onNow you don't need any participation or special magic on any of the tables.
Queries against this like SELECT id, table FROM id_to_table WHERE id = "31ba486f-05ff-11f0-8e4c-a8a15904660a";
Will still use the pk index for each table and will return instantly. You don't even need to keep this view created all the time, just write some SQL to generate the SQL for the view and then execute that, then do your query.
IF you want them to be unique int (ids globally) just make a new sequence and use that sequence whenever you create a new table.
edit: at this point I'm like sure that there is some automated downvoting on this site! why would someone downvoe this? You would think it was political.
So definitely a case of "do not use", but that's only for your sanity, not because it doesn't work as advertised.
E.g. INSERT INTO t_country (id, name) VALUES (1, 'NL') is valid and would not fail in the demonstrated database, but it would result in multiple rows when querying SELECT FROM t_global g WHERE g.id = 1.
A user inserting their own values or resetting the sequence would not necessarily cause immediate unique constraint faulures while duplicate IDs are routed into inherited tables that don't already contain that ID.