pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Eisentraut <peter@eisentraut.org>
To: watermelonmania79@gmail.com
To: pgsql-docs@lists.postgresql.org
Subject: Re: 3.6 Inheritance Documentation
Date: Tue, 8 Aug 2023 11:36:40 +0200
Message-ID: <de8e9b34-0e9d-9fee-c9c5-bb2238c77c2a@eisentraut.org> (raw)
In-Reply-To: <169100604868.635.1178692927881377748@wrigleys.postgresql.org>
References: <169100604868.635.1178692927881377748@wrigleys.postgresql.org>

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)






view thread (2+ messages)

Message-ID: <de8e9b34-0e9d-9fee-c9c5-bb2238c77c2a@eisentraut.org>
Permalink:  ../de8e9b34-0e9d-9fee-c9c5-bb2238c77c2a@eisentraut.org/
Also on:    postgresql.org/message-id/de8e9b34-0e9d-9fee-c9c5-bb2238c77c2a@eisentraut.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: peter@eisentraut.org, watermelonmania79@gmail.com, pgsql-docs@lists.postgresql.org
  Subject: Re: 3.6 Inheritance Documentation
  In-Reply-To: <de8e9b34-0e9d-9fee-c9c5-bb2238c77c2a@eisentraut.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox