Postgresql – Any workarounds for lack of primary key on partitioned tables

partitioningpostgresql-10

I am currently looking at implementing declarative partitioning with PostgreSQL 10. However, one sticking point is that we need to have a foreign key between two such partitioned tables, which is not supported. Is there any workaround or suggestions for alternative ways of doing this anyone can suggest? Or should we use table inheritance instead.

Thanks.

Best Answer

The most common solution is to make an exception and not add the foreign key. I guess this must be very large tables and there are usually not that many of them, so a few exceptions for better performance are typically acceptable. You could try to enforce the foreign key relationship with triggers, though it is messy. I don't know of a better alternative for PostgreSQL 10.