Thread: changing records in inherited tables

changing records in inherited tables

From
Adrian Holovaty
Date:
Hi everybody,

I just started using Postgres a few days ago and love it so far. I've been
trying to wrap my head around its OO features, and I have a question about
table inheritance:

Is it possible to change a record in a parent table in such a way that it is
retroactively inserted into a child table? Here's an example:

CREATE TABLE people (
  id SERIAL,
  first_name VARCHAR(20),
  last_name VARCHAR(30)
);

CREATE TABLE athletes (
  sport VARCHAR(10),
  uniform_no MEDIUMINT
) INHERITS people;

INSERT INTO people (first_name, last_name) VALUES ('John', 'Smith');

What if John Smith later becomes an athlete? Is that best handled by deleting
him from people and reinserting him into athletes while somehow maintaining
the record ID, or is there a better way to do it?

Thanks in advance,
Adrian