Junior — Middle
What is the maximum allowable number of tables you have worked with in a single query in PostgreSQL?
sobes.tech AI
Answer from AI
The maximum number of tables that can be used in a single query in PostgreSQL does not have a fixed limit, but is practically constrained by server resources and query complexity.
PostgreSQL supports complex JOIN operations with many tables, sometimes dozens or even hundreds, but performance and readability of the query significantly deteriorate.
Actual limitations depend on:
- Server memory and processing resources
- Restrictions on recursion depth and execution plan complexity
- Limitations on the number of parameters in a query
In most projects, typically from a few to dozens of tables are used in a single query, and if more are needed, it is better to reconsider the architecture or split the queries.
Example of a simple JOIN with multiple tables:
SELECT a.id, b.name, c.status
FROM table_a a
JOIN table_b b ON a.b_id = b.id
JOIN table_c c ON b.c_id = c.id;