Обсуждение: 3.6 Inheritance Documentation

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

3.6 Inheritance Documentation

От
PG Doc comments form
Дата:
The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/15/tutorial-inheritance.html
Description:

The documentation for inheritance in PostgreSQL is not entirely accurate in
the given example.

In the provided example, the cities table and the capitals table have a
parent-child relationship through inheritance. However, querying the cities
table directly (e.g., SELECT name, elevation FROM cities WHERE elevation >
500;) will not automatically include data from the child table, capitals.
Inheritance in PostgreSQL does not implicitly combine data from parent and
child tables in a single query.

To include data from both the parent and child tables, a UNION or other join
operations must be used, as I previously explained.

The documentation should be corrected to clarify that inheritance does not
automatically combine data from parent and child tables when querying the
parent table directly. It might be updated to provide a better example
demonstrating the use of UNION or JOIN operations to retrieve data from both
parent and child tables.

Re: 3.6 Inheritance Documentation

От
Peter Eisentraut
Дата:
On 02.08.23 21:54, PG Doc comments form wrote:
> In the provided example, the cities table and the capitals table have a
> parent-child relationship through inheritance. However, querying the cities
> table directly (e.g., SELECT name, elevation FROM cities WHERE elevation >
> 500;) will not automatically include data from the child table, capitals.
> Inheritance in PostgreSQL does not implicitly combine data from parent and
> child tables in a single query.

This observation is patently incorrect:

CREATE TABLE cities (
   name       text,
   population real,
   elevation  int     -- (in ft)
);

CREATE TABLE capitals (
   state      char(2) UNIQUE NOT NULL
) INHERITS (cities);

INSERT INTO cities (name) VALUES ('Ithaca');
INSERT INTO capitals (name, state) VALUES ('Albany', 'NY');

SELECT * FROM cities;
   name  | population | elevation
--------+------------+-----------
  Ithaca |            |
  Albany |            |
(2 rows)

SELECT * FROM capitals;
   name  | population | elevation | state
--------+------------+-----------+-------
  Albany |            |           | NY
(1 row)