Query inheritance table : Select Inheritance « Inheritance « PostgreSQL






Query inheritance table

postgres=#
postgres=# -- Inheritance
postgres=#
postgres=# CREATE TABLE cities (
postgres(#   name       text,
postgres(#   population real,
postgres(#   altitude   int
postgres(# );
postgres=#
postgres=# CREATE TABLE capitals (
postgres(#   state      char(2)
postgres(# ) INHERITS (cities);
CREATE TABLE
postgres=#
postgres=# SELECT name, altitude
postgres-# FROM cities
postgres-# WHERE altitude > 500;
 name | altitude
------+----------
(0 rows)

postgres=#
postgres=# SELECT name, altitude
postgres-#    FROM ONLY cities
postgres-#    WHERE altitude > 500;
 name | altitude
------+----------
(0 rows)

postgres=#
postgres=# drop table cities cascade;
NOTICE:  drop cascades to table capitals
DROP TABLE
postgres=#

           
       








Related examples in the same category

1.Selecting with inheritance