Re: 3.6 Inheritance Documentation

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: watermelonmania79(at)gmail(dot)com, pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: 3.6 Inheritance Documentation
Date: 2023-08-08 09:36:40
Message-ID: de8e9b34-0e9d-9fee-c9c5-bb2238c77c2a@eisentraut.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

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)

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message Dan Stoner 2023-08-08 19:05:17 Re: streaming replication depends on matching glibc versions / LOCALE sort order
Previous Message PG Doc comments form 2023-08-08 09:10:46 U+200B ZERO WIDTH SPACE (0xe2 0x80 0x8b) in PostgreSQL documentation